Finding a pixel on screen

Does anyone know how I can find a pixel on screen using RGB value (or any other method) which will work on both mac and windows?

In, I would simply create a loop that will search from point: 0,0 to the whole screen ((My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)), then use an if statement that will return true or false if that pixel = that RGB color.

something like this

But I have no clue how to do this on Xojo. Can anyone help. see the pixel property

First off however you will have to draw the screen into a PICTURE in order to use RGBSurface.

@James - You could use api on both to obtain a screenshot image, putting it into a picture object, and use the graphics.pixel or RGBSurface pixel point of the picture object in reference of the mouse X Y cordinates. This will return the color code. If you search my posts for “screenshot” you should find windows, mac, and linux functions I’ve posted. Btw I’ve been busy working on some projects and should have more webbot material for you tomorrow.

In MBS Plugin we have functions like ScreenshotMBS to get a part of the screen as picture. That would get the picture where RGBSurface can give you color values.

see functions here:

So the best fastest free method is to use window api and cocoa apis… Screenshot method is actually slower than the method I’m about to describe (by MS…negligible).

You can use CGDisplayCreateImageForRect to get a CGImageRef that encompasses the point you’re interested in. Once you have a CGImage, you can get a color value out of it by rendering the image into a memoryblock and Picture.FromData(NameofMemoryBlock)), or by using NSBitmapImageRep’s initWithCGImage and then colorAtX:y:.

In obj C it would look like the following (easy xojo convert :-)):

NSColor *MyColorAtScreenCoordinate(CGDirectDisplayID displayID, NSInteger x, NSInteger y) { 

CGImageRef image = CGDisplayCreateImageForRect(displayID, CGRectMake(x, y, 1, 1)); 

NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:image]; 


NSColor *color = [bitmap colorAtX:0 y:0];
 [bitmap release]; }

Windows has a singular built-in function which I’m sure MBS plugins use called BitBlt to grab the screen and even faster than using Xojo’s builtin functions for RGBSurface/graphics.Pixel, is the windows GetPixel function itself.

You can learn about those here:

Or you can use a premade snippet of xojo code I posted a while back for the screenshot method…already completed guaranteed to work :-p

See this posting for the xojo code