Page 1 of 1
Getting the pixel color of X,Y on an image
Posted: Mon Feb 07, 2011 2:30 pm
by richh
I have an image that is 400, 400 and I am trying to get the color of the pixel at 200,200. I have been searching through the dictionary for a way to do this and now I am stumped.
thoughts on what i can use?
Re: Getting the pixel color of X,Y on an image
Posted: Mon Feb 07, 2011 3:21 pm
by Dixie
Hi Rich...
Put this into the script of your image ... and, err... move the mouse around..
Code: Select all
on mouseWithin
put item 1 of the mouseLoc - item 1 of the topLeft of me into X
put item 2 of the mouseLoc - item 2 of the topLeft of me into Y
put the mouseColor into thePixColor
put X & "," & Y && "/" && thePixColor
end mouseWithin
be well
Dixie
Re: Getting the pixel color of X,Y on an image
Posted: Mon Feb 07, 2011 3:24 pm
by kray
richh wrote:I have an image that is 400, 400 and I am trying to get the color of the pixel at 200,200. I have been searching through the dictionary for a way to do this and now I am stumped.
thoughts on what i can use?
There are two ways - the shortcut (which only works if the image is visible, on screen, and not obscured by anything) and the more complex way:
Shortcut: Move the cursor to that location programmatically and then ask for the mouseColor:
Code: Select all
put the mouseLoc into tOldLoc
set the mouseLoc to globalLoc((the left of img 1+200),(the top of img 1+200))
put the mouseColor into tColor -- you'll use this, it's an RGB value
set the mouseLoc to tOldLoc
Complex: Examine the imageData:
See
this tip for info on how to do that.
Re: Getting the pixel color of X,Y on an image
Posted: Mon Feb 07, 2011 3:41 pm
by richh
I am very appreciative with how fast you both got back to me and I will take some time looking at your example code and trying to implement.
I will keep you both posted with how I make out.
thank you again

Re: Getting the pixel color of X,Y on an image
Posted: Mon Feb 07, 2011 6:43 pm
by jmburnod
Hi Richh,
For an other way, you can look at the imagedata entry of the LC dictionary
(Poor frenchie, It is difficult for me to explain in English)
All the best
Jean-Marc