Sign in to follow this  
Followers 0
Vossen

Get Pixel Color from Image

7 posts in this topic

When I searched this forum, I couldn't find any way to get a pixel color from an image.

Done some research and found this on a french AutoIt forum (http://www.autoitscript.fr/forum/viewtopic.php?f=3&t=2993&start=0)

#include <GDIPlus.au3>

$sv_ImageSource = @ScriptDir & "\Source.jpg"
$iPosX = 253
$iPosY = 291

_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile($sv_ImageSource)

MsgBox(0, "Pixel Color", _GDIPlus_BitmapGetPixel($hImage, $iPosX, $iPosY))

_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()

Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
    Local $tArgb, $pArgb, $aRet
    $tArgb = DllStructCreate("dword Argb")
    $pArgb = DllStructGetPtr($tArgb)
    $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "ptr", $pArgb)
    Return "0x" & Hex(DllStructGetData($tArgb, "Argb"), 6)
EndFunc

Hope it will be useful for someone else too!

1 person likes this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

@Vossen

Its possible with _PixelGetColor UDF but the script isn't available anymore...(until Manadar reupload it)

Thank you for your simple and useful UDF !

Cheers, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

When I searched this forum, I couldn't find any way to get a pixel color from an image.

Done some research and found this on a french AutoIt forum (http://www.autoitscript.fr/forum/viewtopic.php?f=3&t=2993&start=0)

#include <GDIPlus.au3>

$sv_ImageSource = @ScriptDir & "\Source.jpg"
$iPosX = 253
$iPosY = 291

_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile($sv_ImageSource)

MsgBox(0, "Pixel Color", _GDIPlus_BitmapGetPixel($hImage, $iPosX, $iPosY))

_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()

Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
    Local $tArgb, $pArgb, $aRet
    $tArgb = DllStructCreate("dword Argb")
    $pArgb = DllStructGetPtr($tArgb)
    $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "ptr", $pArgb)
    Return "0x" & Hex(DllStructGetData($tArgb, "Argb"), 6)
EndFunc

Hope it will be useful for someone else too!

Next time, please search these forums using the export function before posting. The export function you should have searched on is "GdipBitmapGetPixel".

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Next time, please search these forums using the export function before posting. The export function you should have searched on is "GdipBitmapGetPixel".

Sorry, m8, not to be offensive, but do you have to be such an a**?

I may need to search better, but then you'll have to read better!

As I said: "When I searched this forum, I couldn't find any way to get a pixel color from an image" and if I had no idea how to do it, how should I then know I would have to search for GdipBitmapGetPixel?

Atleast I found what I were looking for and I was nice enough to post it here for others usage.

Vossen - Kinda pissed!

Edited by Vossen

Share this post


Link to post
Share on other sites

How was he an ass? He was merely pointing out what you should have searched for so you would know next time.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This kinda sentence make me kinda pissed: "Next time, please search these forums using the export function before posting."

"Next time," like he just helped me with something really easy, which I just could have searched for in a few seconds,

and the fact that he tells me to search, although I pointed out in the very start of my post that I searched without luck.

Also that he points out what I should have searched for, which is pretty obvious now that I found it.

It might not be what he did, but the way he did it, imo. he should just have left that comment as it was, not there.

Edit: I have to admit, that I may have used a wrong word, when I wrote it I was kinda frustrated and I may have used a wrong choise of words. Sort of regret that, sorry.

Edit: Also as you might see I linked to a French forum, even had to Google Translate it to understand the language just abit, how would I have found that without searching? I searched here for quite a while, I found that GDI+ had to be a way, though eventually I gave up and moved on to Google. After a few hours of searching I found what I needed. Went from scratch to what I needed all by myself, instead of just instant posting here for help and it makes me frustrated that you get the "Next time, please search these forums using the export function before posting." after a few hours of search here and on Google.

Edited by Vossen

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0