Pixel Colour
Hello,
Might anyone here have some good code for reading the pixel colour in a bitmap? I simply want to compare each pixel to the colour white using an If statement. Nice and simple, but I seem to be having a lot of problems with it. My current code does not seem to work.
Help would be great!
Thanks,
Dachande
the trick is to know (or find out) what format the bitmap is in.
the color values for a 8-bit bitmap are not the same as those for a 16-, 24-, or 32-bit bitmap.
the color values for a 8-bit bitmap are not the same as those for a 16-, 24-, or 32-bit bitmap.
assuming you have decoded the file, and have an array of all the pixels in the bitmap (eighter an unsigned char,unsigned short, or unsigned int depending on resolution);
int nWidth; // holds the width of the bitmap in pixels
unsigned char *pData; // if 8 bits per pixel
unsigned short *pData; // if 16 bits per pixel
// if 24 bits per pixel, it gets complicated cos you have to use unsigned char triplets unsigned char pData[ R ][ G ]<br>unsigned int pData; // if 32 bits per pixel<br>int x,y; // coordinates of pixel t read<br><br>PixelReaded = pData[(y*nWidth)+x];<br><br>and thats it, not sure if thats your question though, that is subject to optimization (removing the multiply), but it is said that multipling is not as slow as it used to be back in the days. <br><br><a href="http://www.aeonsrpg.com"><img src="http://www.aeonsrpg.com/images/AeonsSmall.png" width="149" height="25" border="0"></a><br><br>Edited by - kwizatz on January 3, 2002 2:05:04 PM<br><br>Edited by - kwizatz on January 3, 2002 2:05:39 PM
int nWidth; // holds the width of the bitmap in pixels
unsigned char *pData; // if 8 bits per pixel
unsigned short *pData; // if 16 bits per pixel
// if 24 bits per pixel, it gets complicated cos you have to use unsigned char triplets unsigned char pData[ R ][ G ]<br>unsigned int pData; // if 32 bits per pixel<br>int x,y; // coordinates of pixel t read<br><br>PixelReaded = pData[(y*nWidth)+x];<br><br>and thats it, not sure if thats your question though, that is subject to optimization (removing the multiply), but it is said that multipling is not as slow as it used to be back in the days. <br><br><a href="http://www.aeonsrpg.com"><img src="http://www.aeonsrpg.com/images/AeonsSmall.png" width="149" height="25" border="0"></a><br><br>Edited by - kwizatz on January 3, 2002 2:05:04 PM<br><br>Edited by - kwizatz on January 3, 2002 2:05:39 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement