#### Archived

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

# Extract Pixel Colors...

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

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

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 48
• ### Forum Statistics

• Total Topics
632637
• Total Posts
3007578
• ### Who's Online (See full list)

There are no registered users currently online

×