ReadPixel() Question

BlitzPlus Forums/BlitzPlus Programming/ReadPixel() Question

Hardrive(Posted 2007) [#1]
I understand how to use ReadPixel. However, I don't understand the value it returns. I'm getting seemingly random numbers when I run it, like in the range of negative thousands.

Anyway, I'm wondering how I can convert the value ReadPixel returns into a standard RGB value, and then how to convert it back to a value that WritePixel consumes.

Thanks!


CS_TBL(Posted 2007) [#2]
"The returned colour value is in the form of an integer that contains the alpha, red, green and blue values of the pixel. "

So, the int value (=4 bytes) contains bytes for alpha, red, green and blue "encoded" in one value.

try this:
value=65539
Notify "x--- "+((value Shr 24) And 255)
Notify "-x-- "+((value Shr 16) And 255)
Notify "--x- "+((value Shr 8 ) And 255)
Notify "---x "+( value         And 255)
End



Moore(Posted 2007) [#3]
Here are a few functions I find usefull.

Function getAlpha(colour)
	Return (colour Shr 24) And $ff
End Function

Function getRed(colour)
	Return (colour Shr 16) And $ff
End Function

Function getGreen(colour)
	Return (colour Shr 8) And $ff
End Function

Function getBlue(colour)
	Return colour And $ff 
End Function

Function returnColor(r, g, b)
	colour = b + (g Shl 8) + (r Shl 16)
	Return colour
End Function

Function setColor(colour)
 Color getRed(colour), getGreen(colour), getBlue(colour)
End Function



Hardrive(Posted 2007) [#4]
Thanks so much, both of you. That's all that I needed.