on tTopOfpaint n -- (n= short name of an image)
put the ticks into old
put the rect of image n into Lar
put item 1 of LaR into LaG
put item 3 of LaR into LaD
put item 2 of LaR into LeT
put item 4 of Lar into LeB
put 0 into bufTop
repeat until bufTop <> 0
repeat with i = LaG to LaD
put i & "," &LeT into LeP
set the screenMouseLoc to globalLoc(LeP)
put the mousecolor into LaMC
wait 1 milliseconds -- to watch the progress
if LaMC <> "255,255,255" then
put LeP&LaMC &return into bufTop
choose browse tool
dansmes LeT&& the ticks - old
exit tTopOfpaint
end if
end repeat
add 1 to LeT
end repeat
end tTopOfpaint
on DansMes t
put t
end DansMes
This approach would only work if nothing was overlapping the image - including other application windows. You're better off looking at the imageData property of the image control.
function TopOfPaint pImage
put the imageData of image pImage into tImageData
put the width of image pImage into tWidth
put the height of image pImage into tHeight
put empty into tTopBuffer
put 1 into tByteIndex
put binaryEncode("CCCC",0,255,255,255) into tComparePixelData
repeat with tRow = 1 to tHeight
repeat with tColumn = 1 to tWidth
put byte tByteIndex to tByteIndex + 3 of tImageData into tPixelData
if tPixelData is not tComparePixelData then
local tAlpha, tGreen, tRed, tBlue
get binaryDecode("CCCC",tPixelData,tAlpha,tRed,tGreen,tBlue)
put tRow, tColumn, tRed, tGreen, tBlue into tTopBuffer
return tTopBuffer
end if
end repeat
end repeat
return empty
end TopOfPaint
function TopOfPaint pImage
put the imageData of image pImage into tImageData
put the width of image pImage into tWidth
put the height of image pImage into tHeight
put empty into tTopBuffer
put 1 into tByteIndex
put binaryEncode("CCCC",0,255,255,255) into tComparePixelData
repeat with tRow = 1 to tHeight
repeat with tColumn = 1 to tWidth
put byte tByteIndex to tByteIndex + 3 of tImageData into tPixelData
if tPixelData is not tComparePixelData then
local tAlpha, tGreen, tRed, tBlue
get binaryDecode("CCCC",tPixelData,tAlpha,tRed,tGreen,tBlue)
put tRow, tColumn, tRed, tGreen, tBlue into tTopBuffer
return tTopBuffer
end if
add 4 to tByteOffset
end repeat
end repeat
return empty
end TopOfPaint
Hi Jan,
If you increment tByteindex and not tByteOffset
TopOfPaint return the color of the first pixel <> 255,255,255 but not the location of the pixel (tRow and tColumn still = 1)
function TopOfPaint pImage
put the imageData of image pImage into tImageData
put the width of image pImage into tWidth
put the height of image pImage into tHeight
put empty into tTopBuffer
put 1 into tByteIndex
put binaryEncode("CCCC",0,255,255,255) into tComparePixelData
repeat with tRow = 1 to tHeight
repeat with tColumn = 1 to tWidth
put byte tByteIndex to tByteIndex + 3 of tImageData into tPixelData
if tPixelData is not tComparePixelData then
local tAlpha, tGreen, tRed, tBlue
get binaryDecode("CCCC",tPixelData,tAlpha,tRed,tGreen,tBlue)
put tRow, tColumn, tRed, tGreen, tBlue into tTopBuffer
return tTopBuffer
end if
add 4 to tByteIndex
end repeat
end repeat
return empty
end TopOfPaint
Aargh, silly computer - do as I think, not as I say
You're right, I meant to increment tByteIndex; however, in my tests, it does return the row and column correctly. You can always set a breakpoint and debug to see what's in there when it has found a different color.
In that case, you need to work with the alphaData property as well.
Whereas the imageData is comprised of 4 bytres per pixel, the alphaData is just one byte per pixel, so you can create a similar loop.
-- the location of the first (top) pixel no transparent of an image. 0,0 = the topleft of the image
function TopOfPaintAlpha pImage
put the alphadata of image pImage into tAlphaData
put the width of image pImage into tWidth
put the height of image pImage into tHeight
put empty into tTopBuffer
put 1 into tByteIndex
repeat with tRow = 1 to tHeight
repeat with tColumn = 1 to tWidth
put charToNum(char tByteIndex of tAlphaData) into tPixelData
if tPixelData is not 0 then
put tRow, tColumn into tTopBuffer
return tTopBuffer
end if
add 1 to tByteIndex
end repeat
end repeat
return empty
end TopOfPaintAlpha
if you are working with images the alphadata can go from 0 to 255 to give shades of transparencies. If you want an index of complete transparency versus complete opacity the maskData gives you either 0 or 255, without the intermediate values of the alphaData. At times that can be useful. Otherwise the maskData is similar to the alphaData, one byte for each pixel.