Archived

This topic is now archived and is closed to further replies.

dachande

Pixel Colour

Recommended Posts

dachande    162
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Kwizatz    1392
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 ][ B ]
unsigned int pData; // if 32 bits per pixel
int x,y; // coordinates of pixel t read

PixelReaded = pData[(y*nWidth)+x];

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.



Edited by - kwizatz on January 3, 2002 2:05:04 PM

Edited by - kwizatz on January 3, 2002 2:05:39 PM

Share this post


Link to post
Share on other sites