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

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
neo42
Posts: 83
Joined: Tue Mar 01, 2011 10:20 pm

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

Post by neo42 » Mon May 02, 2011 9:40 pm

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.

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

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

Post by BvG » Tue May 03, 2011 12:10 am

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.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Post Reply