readpixel return negative value !

BlitzPlus Forums/BlitzPlus Programming/readpixel return negative value !

hub(Posted 2003) [#1]
Hi !
i don't understand why in this case readpixel return a negative value, not an integer. Could you help me please ? I just want read the pixel color at x,y and compare it to 255,0,255 !
Thanks !

load 8 or 24 bits png image as mask
Mask = LoadImage ("masque.png")
...

col = ReadPixel (x,y, ImageBuffer(Mask)

(rgb = 255,0,255)
MaskColor = 255 Or (0 Shl 8) Or (255 Shl 16)

if MaskColor = col then
 ;collision
end if

...




Floyd(Posted 2003) [#2]
The first 8 bits are alpha. This is used in textures.
When ReadPixel is used on an image the alpha value is always 255.
This corresponds to fully opaque.

ReadPixel(x,y) And $FFFFFF

This zeroes out the first 8 bits and gives the RGB value you expect.


Beaker(Posted 2003) [#3]
col = ReadPixel (x,y, ImageBuffer(Mask) And $FFFFFF
should do it.

Strips the alpha values which can make it appear like a negative.


hub(Posted 2003) [#4]
Thanks Floyd & MasterBeaker !