Jump to content
  • Advertisement


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


Pixel Colour

This topic is 6044 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!