• Announcements

Archived

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

Extract Pixel Colors...

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 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 on other sites
Okay now i stored the pixel data for a 4-Bit .bmp into a char but every byte is 2 pixel, how can i read the second pixel,

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 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 on other sites
quote:
I don''t know if this is the right way, Is it???

Eternally useful advice: try it out.

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

• Partner Spotlight

• Forum Statistics

• Total Topics
627677
• Total Posts
2978589

• 11
• 12
• 10
• 12
• 22