Find a color

bunze

Well-known member
Joined
Aug 4, 2005
Messages
52
Location
Adirolf
Programming Experience
1-3
Is there a way to find a color on the screen, like blue 255? I want to find the x,y location of it.
 
I've seen it in another program. It "scans"the screen for a certain color like 255 blue and gets it's xy. In the end,I want tomove the mouse/cursor the the pixel where the color is.I could move the cursor If I can find the xy.
 
Last edited:
I was thinking something like this, but theres prolly an easier way:

dim cp as point
For Each cp In Screen.primaryscreen.something :(
if color of cp = blue then
move mouse
end if
Next cp

Now, I know scanning the whole screen would take a while, So I'd add something to only scan like, 30 pixels on both sides on the cursor, and above and below it too.
 
Last edited:
"This is how i'd do it. Get the window handle of your screen, create rgb variables (if you're using a dialog, nicer that way) and use GetPixel."

Someone said...

I forgot to say, I dont want to scan the entire screen, just inside one program. Not my program, It is another program named 3xen.exe. I guess I need to find the window handle and then how would I search for a pixel color directly inside of the 3xen program?
 
I quoted what someone said, I was not talking with myself.

Someone said to get the handle of the program 3xer.exe and then create rgb variables (if you're using a dialog, nicer that way) and use GetPixel.

I want to scan the program for a red pixel (well a color I specify) and move the mouse to it. I know scanning the whole program would take a while so I would set it to scan an area of 40 pixels by 40 pixels in the middle of the screen.
 
got to http://www.autoitscript.com/autoit3/ and you will see a link to autoitx. This is an activex object you can use. it has method to do just what you want to do.

from the autoit ref manual:

PixelSearch
Searches a rectangle of pixels for the pixel color provided.


PixelSearch left, top, right, bottom, color [, shade-variation] [, step]]




Parameters

leftleft coordinate of rectangle.toptop coordinate of rectangle.rightright coordinate of rectangle.bottombottom coordinate of rectangle.colourColour value of pixel to find (in decimal or hex).shade-variation[optional] A number between 0 and 255 to indicate the allowed number of shades of variation of the red, green, and blue components of the colour. Default is 0 (exact match).step[optional] Instead of searching each pixel use a value larger than 1 to skip pixels (for speed). E.g. A value of 2 will only check every other pixel. Default is 1.


Return Value

Success:Returns a string containing the pixel's coordinates in the format "x,y"Failure:Sets oAutoIt.error to 1 if color is not found.


To use it:

Add the autoitx reference to your project
import it into your app
create and instance
call the method

have fun!
 
Back
Top