color of a pixel without use of mouseColor

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
fm31
Posts: 22
Joined: Tue Apr 23, 2013 2:08 pm

color of a pixel without use of mouseColor

Post by fm31 » Mon Oct 26, 2015 11:39 am

hello EveryBody

I have an interface with many objects inside (buttons, graphics, ...) in the background .some of these objects are moving alone depending random trajectories. I need to know the color of the pixel in a X,Y part of the interface.

I know the use of mouseColor who give us what color the mouse is over and the background of this interface is not an image (imagedata property is not usable)

I need to know the color of the interface under the four corners of a square . This square is controlled with the mouse and I need to compare the fours colors (one by corner) at each time I move the square with the mouse. I can't use the mouseColor function because the mouse is inside the square

If someone has a solution, I will be grateful

Thanks for help

fm31

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

Re: color of a pixel without use of mouseColor

Post by jmburnod » Mon Oct 26, 2015 12:04 pm

Hi fm31,

I use this script, it works for my needs (a kind of answer color) but sometimes it return some strange results as you can see at the last line
I hope this help

Code: Select all

function getMyPixColor pImage,x,y
   put x - the left img pImage + 1 into tImgX
   put y - the top of img pImage + 1 into tImgY
   put the imageData of image pImage into tData
   put the width of image pImage into tWidth
   put the height of image pImage into tHeight
   put tImgX into tColumn
   put tImgY into tRow
   put tWidth * tRow * 4 into tAllRows
   put tColumn * 4 into tTheColumns
   put tAllRows + tTheColumns into tByte -- for loc 1,1 it gives byte 4, see above how the 4 bytes of the pixel work
  -- we want byte 2 to 4 of the pixel
   put charToNum (char tByte - 2 of tData) into tRed -- byte 
   put charToNum (char tByte - 1 of tData) into tGreen
   put charToNum (char tByte of tData) into tBlue
   put tRed & comma & tGreen & comma & tBlue into tWholeRGB
   return tWholeRGB -- & cr & the mousecolor -- compare results
end getMyPixColor
Best regards
Jean-Marc
https://alternatic.ch

Post Reply