Archived

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

Extract Pixel Colors...

This topic is 5869 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

I need some C++ code to extract the color data of every pixel in a 16-color .BMP into an array of ints. I''m planing on using the putpixel(); function in BGI to display the picture Can some one please help me...

Share this post


Link to post
Share on other sites
http://www.wotsit.org has information about many filetypes. You''ll find all the information about the BMP format there. Also, at the FAQ at www.cprogramming.com, one of the topics is "DISPLAYING A PICTURE FILE." This covers the loading of an 8-bit BMP; you may find it helpful even though you''re working with 16 bit BMPs.

Share this post


Link to post
Share on other sites
You need to use a binary mask to extract the nibble (4bits) that you want:

    
#define HIGH_NIBBLE(x) (x >> 4)

#define LOW_NIBBLE(x) (x & 0x0F)


To get the highest four bits you shift everything over to the right by 4 bits. To get the low four bits you and with 0x0F which is 00001111 in binary. Since x and 0 is 0 and x and 1 is x, this effectively clears out the top 4 bits.

Edited by - invective on November 14, 2001 12:30:30 PM

Share this post


Link to post
Share on other sites
okay I load the byte into a

char color;

and then I do it like this

int low = color && 0x0f;
int high = (color >> 4);

I don''t know if this is the right way, Is it???

Share this post


Link to post
Share on other sites
yeah i have, but it doesn't read all the pixel it skips every other pixel. The first comes out right but the second is just a 1,(is doesn't matter which color the second pixel is it just keeps on coming out as a 1) or is that how it's suppose to be??? or am I doing something wrong??...


Edited by - Asker on November 18, 2001 9:16:46 AM

Share this post


Link to post
Share on other sites