Page 1 of 1

how do I determine what the color of a given pixel is?

Posted: Mon May 02, 2011 9:40 pm
by neo42
How do I detect the color of what has been drawn to the screen?

For example, I've used "set the pencolor to black", "choose pencil" and "click at x,y" to do some code based painting but now I want the code to be able to know what the color of any given pixel on screen is.


Do I have to import a snapshot and then use some function to read the color of pixels in an image? How would I detect the color of pixels in an image?


I have a similar thread in the other forum on here but this one is more to the point and probably in the right place.

Re: how do I determine what the color of a given pixel is?

Posted: Tue May 03, 2011 12:10 am
by BvG
one way to do this is to detect the mouseColor. However, there's no built in way to get any arbitrary pixel location onscreen. TO work around that,you can lock the screen, store the current mouse position, then set it to where you want to check, get the mouseColor, set the mouseLoc back, and then continue. This is fast enough for the user to not realise it happens.

Another way, if you want to know the pixel of a image, is to get the imagedata, and analyze that. However, this can be slow for larger images.