pixmap.readpixel(x,y)
BlitzMax Forums/BlitzMax Beginners Area/pixmap.readpixel(x,y)
| ||
I currently need to take the RGB values from a pixel within a pixmap. I don't really understand the value given from this function or how to convert and extract the RGB values from the output. |
| ||
It's prolly ARGB or something. B=value&$FF G=(value shr 8)&$FF R=(value shr 16)&$FF A=(value shr 24)&$FF or something.. :P |
| ||
curiously enough, I had to figure out the very same thing today. In a pixmap, color data is stored as a 32 bit integer. which means 8 bits(ie a number from 0 to 255) for each channel from scrounging the forums I have found that most people use hex numbers rather than binary or decimal numbers to represent this integer. bits 24-31 pixel alpha bits 16-23 pixel red bits 8-15 pixel green bits 0-7 pixel blue the readpixel function returns this 32 bit number. if you print the result of readpixel it will likely be large negative number. I have no idea why it's negative, but if you print it enclosed in the bin() function, you will see the actual bits, the first 8 of which are alpha, the second 8 red etc... I made some code to show how to extract the rgb values. Hope that helps Function rgb(pixelValue%) Local r%, g%, b% pixelValue = ($00ffffff & pixelvalue) 'gets rid of the alpha bits making the number make sense r = pixelvalue/$10000 pixelValue = ($00ffff & pixelvalue) 'removes the r value Print r g = pixelvalue/$100 Print g pixelValue = ($00ff & pixelvalue) 'removes the g value leaving only b b = pixelvalue Print b EndFunction |
| ||
// |
| ||
Thanks, I got it working with all the help. Now my heightmaps can be read and rendered from textures. |