Pixel Question

Bob Warren bobwarren at howsoft.com
Thu Mar 23 23:54:57 EST 2006


Recently, Scott Rossi wrote:

 >Recently, Bob Warren wrote:

 >> > Suppose I have 2 cards in a stack and I am moving the mouse over 
the top
 >> > card (naturally). I want to know what colour is under the mouse 
pointer
 >> > in a corresponding position on the 2nd card which is hidden 
underneath.

 >
 > I believe this function will retrieve the pixel color of a pixel in any
 > image using the X,Y position of the pixel as measured from the topleft of
 > the image.  Pass the long ID of the image and the X,Y coordinates as
 > follows:
 >
 > on mouseUp
 >   answer retrievePixelColor(long id of myImage,5,5)
 > end mouseUp
 >
 > function retrievePixelColor pObj,X,Y
 >   put imageData of pObj into tData
 >   put ((Y-1) * width of pObj * 4) + ((X-1)*4) into P
 >   repeat with N = 2 to 4
 >     put charToNum(char (P+N) of tData) & "," after tColor
 >   end repeat
 >   delete last char of tColor
 >   return tColor
 > end retrievePixelColor
 >
 > Let me know if this works for you.
 >
 > Regards,
 >
 > Scott Rossi
 > Creative Director
 > Tactile Media, Multimedia & Design

-------------------------------------------------

Thanks a lot Scott, almost there!

Using a mouseMove routine on the top card such as:-

on mouseMove
   put retrievePixelColor(long id of image "myImage" \
   of card "Card2",the mouseH,the mouseV) into field \
   "ColourRGB" of card "Card1"
end mouseMove

- it works quite nimbly, even on my old Pentium II.

However, there are some slight inaccuracies in the colours reported.
For example:

RED 255,0,0 is reported as 254,0,0
GREEN 0,128,0 is reported as 0,128,1
BLUE 0,0,255 is reported as 0,0,254
YELLOW 255,255,0 is reported as 255,255,1

WHITE 255,255,255 is OK.

Without a better analysis of your function, I cannot see immediately 
what the trouble is. Can you see it Scott?

Regards,
Bob








More information about the use-livecode mailing list