Getting the pixel color of X,Y on an image

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
richh
Posts: 41
Joined: Tue Jan 25, 2011 8:48 pm

Getting the pixel color of X,Y on an image

Post by richh » Mon Feb 07, 2011 2:30 pm

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?
- Rich

LiveCode 4.6.4
Dell Latitude E6400 running Windows XP SP3 / Mac Pro, Macbook Pro & Mac Mini running OS X 10.6.4

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Getting the pixel color of X,Y on an image

Post by Dixie » Mon Feb 07, 2011 3:21 pm

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

kray
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 56
Joined: Sat Apr 08, 2006 5:28 pm
Contact:

Re: Getting the pixel color of X,Y on an image

Post by kray » Mon Feb 07, 2011 3:24 pm

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.
Ken Ray
Sons of Thunder Software
Email: kray@sonsothunder.com
Web site: http://www.sonsothunder.com

richh
Posts: 41
Joined: Tue Jan 25, 2011 8:48 pm

Re: Getting the pixel color of X,Y on an image

Post by richh » Mon Feb 07, 2011 3:41 pm

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 :D
- Rich

LiveCode 4.6.4
Dell Latitude E6400 running Windows XP SP3 / Mac Pro, Macbook Pro & Mac Mini running OS X 10.6.4

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Getting the pixel color of X,Y on an image

Post by jmburnod » Mon Feb 07, 2011 6:43 pm

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
https://alternatic.ch

Post Reply