How to get individual R,G,B values of a pixel?

Blitz3D Forums/Blitz3D Beginners Area/How to get individual R,G,B values of a pixel?

Galdy(Posted 2011) [#1]
I was wondering if and how you can get the individual rgb values of a pixel. Red=value, G=Value, B=Value

I tried
rgb=readpixel(x,y)and $ffffff,

but it gives one long number which i don't know what to do with.


Galdy(Posted 2011) [#2]
Nevermind. Found the info in the online manual via the following commands
GetColor x,y

ColorRed(),ColorGreen(), ColorBlue()

Last edited 2011


Matty(Posted 2011) [#3]
There is another way which is as follows:

rgb=readpixel(x,y)

red=(rgb shr 16) and 255
green=(rgb shr 8) and 255
blue=rgb and 255

;and to convert back from individual components to rgb do the following

rgb = (red shl 16) or (green shl 8) or blue



Warner(Posted 2011) [#4]
Depending on what you use this for, it might be good to know that the return values could differ depending on the bitdepth of the current display mode: In 16-bit display mode, some of the precision is lost when writing onto the screen. That results in values that are slightly off compared to the same program running on a 32-bit display mode. Again, info only applies depending on what you use this for.