Jump to content
Sign in to follow this  
Guest arena

Problems With PixelGetColor

Recommended Posts

Guest arena

I need to set 2 different events based on 3 possible images appearing on my screen.

So I used the example provided in the AutoIt help file for PixelGetColor:


$var = PixelGetColor( 10 , 100 )

MsgBox(0,"The decmial color is", $var)

$c = PixelGetRGB(10,100)

MsgBox(0,"The RBG Pixel Color is", $c[1] & "," & $c[2] & "," & $c[3])


; Returns an array with element1=RED, element2=GREEN, element3=BLUE

Func PixelGetRGB($x, $y)

$hex = Hex(PixelGetColor($x, $y), 6)

$r = Dec(StringRight($hex, 2)) & "|"

$g = Dec(StringMid($hex, 3,2)) & "|"

$b = Dec(StringLeft($hex, 2))

Return StringSplit($r & $g & $b, "|")


So I open a bmp screen capture and move the mouse over the desired pixel (22,999) and I get a decimal return of 14933984. But then I tried the others and got the same decimal return of 14933984 even though they were different colors. So I thought even though I moved the mouse cursor over the desired pixel it was getting the color for the pixel at 10,100 each time according to the pixel location in the script. So I changed the value in the script to ( 22 , 999) but get -1 as the result.

Any ideas? Can anyone explain how to enter the coordinates that will capture the color of the correct pixel?

Thanks in advance for any help.

Share this post

Link to post
Share on other sites

Your example looks ok to me ...

Did you check the position & color with AU3_Spy.exe ?

by the way , there is an issue/change with the sequence of the colors.. check out this post: #17639

here's an alternative way for your function:

; Returns an array with element1=RED, element2=GREEN, element3=BLUE
Func PixelGetRGB($X, $Y)
   local $A_RGB[4]
   $HEX = Hex(PixelGetColor($X, $Y), 6)
   $A_RGB[1] = Dec(StringRight($HEX, 2))
   $A_RGB[2] = Dec(StringMid($HEX, 3, 2))
   $A_RGB[3] = Dec(StringLeft($HEX, 2))
   Return $A_RGB
EndFunc  ;==>PixelGetRGB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
Live for the present,
Dream of the future,
Learn from the past.

Share this post

Link to post
Share on other sites
Guest arena

Well I used a mouse cursor position finding script and I was able to get the correct mouse position, and then edit this into the PixelGetColor script to get the value for the pixel in the position I wanted on screen. However, even though the color appears the same to me in each picture, I'm getting three different decimal values for the color ranging from low 7000000 to mid 8000000.

So I want the script to excecute a certain function when this certain color appears on screen, but in each of the screen captures in the position where the color appears AutoIt gives me several different decimal values for several different shades of the same color (lightish green).

So I'm confident I have the right pixel position, but I'm wondering if there is any way I can use the line "If PixelGetColor( x , y ) = 0000000 Then..." but instead of using only a single seven digit decimal value for the color use a range instead to make sure the script will perform the correct function even if the very specific shade of green doesn't show up, ie "If PixelGetColor(141,1001) = 7000000 to 8500000 Then..."

Is there any way to have the script execute the function if any shade of green appears in the right position rather than a specific value?

Also I tried using Auto Spy but couldn't really get it figured out, I think since the specific pixel im after appears in a different location in paint (due to the toolbar on the right) rather than where it will appear in the kind of full screen mode I need for the script so the positioning is getting confused. Also Auto Spy didn't list any color...Let me know if I'm still doing something wrong.

Thanks again.

Edited by arena

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...