Page 1 of 1
Detect the color of a pixel anywhere within the window
Posted: Mon May 02, 2011 9:00 pm
by neo42
I thought I could use a combination of "mousecolor" and "click at x,y" to determine the color of pixels anywhere in the window, but it seems to be driven by where the user has the mouse cursor.
Code: Select all
choose browse
click at x, y
answer the mousecolor
How do I detect the color of what has been drawn on 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.
Re: Detect the color of a pixel anywhere within the window
Posted: Mon May 02, 2011 9:19 pm
by jmburnod
Hi,
Look at brushColor
You can try also
Code: Select all
on mousemove
put the mousecolor
end mousemove
It get the current mousecolor only when the mouse is up
Jean-Marc
Re: Detect the color of a pixel anywhere within the window
Posted: Mon May 02, 2011 9:36 pm
by neo42
jmburnod wrote:Hi,
Look at brushColor
You can try also
Code: Select all
on mousemove
put the mousecolor
end mousemove
It get the current mousecolor only when the mouse is up
Jean-Marc
Very confused.
Brushcolor appears to let you change the color you will paint/draw with. - that is not I'm asking about
Also, how would that code segment help? I need to be able to detect the color of a pixel, via code only, and I believe the mousecolor command won't help me at all because that's based on where the mouse cursor is.
Thanks though...
Re: Detect the color of a pixel anywhere within the window
Posted: Tue May 03, 2011 12:00 am
by bn
Hi Neo42,
the shurest thing is to use a snapshot. At least I dont know of anything else. I made a little stack that takes a snapshot of 1by1 pixel.
You read out the color RGB value by parsing the imagedata of an image.
Have a look at the script.
I saw your post over at the talking Livecode section. Dont worry, people will answer here as well.
Kind regards
Bernd
Re: Detect the color of a pixel anywhere within the window
Posted: Tue May 03, 2011 12:07 am
by FourthWorld
You can also set the screenMouseLoc to the specified location - just remember to set it back after you get the color:
Code: Select all
on mouseUp
put PixelColor(500,500)
end mouseUp
function PixelColor x,y
put the screenMouseLoc into tSaveLoc
set the screenMouseLoc to x,y
put the mouseColor into tColor
set the screenMouseLoc to tSaveLoc
return tColor
end PixelColor
Re: Detect the color of a pixel anywhere within the window
Posted: Tue May 03, 2011 12:15 am
by bn
Hi Richard,
that works very well. I thought of it but did not even try because I thought the cursor would jump around. But it is so fast that one does not notice.
Thanks, it is a lot easier than taking a snapshot etc.
Kind regards
Bernd
Re: Detect the color of a pixel anywhere within the window
Posted: Tue May 03, 2011 12:59 am
by FourthWorld
I avoided it for a long time myself for the same reason, until one day I was desperate enough to try it and was pleased with the result.

Re: Detect the color of a pixel anywhere within the window
Posted: Wed May 11, 2011 1:57 pm
by neo42
I'll have to try some of these out. I ended up going a different route in that project but I will still have a use for this later. Thank you!
Re: Detect the color of a pixel anywhere within the window
Posted: Wed May 11, 2011 2:03 pm
by neo42
I'll have to try some of these out. I ended up going a different route in that project but I will still have a use for this later. Thank you!