Extract Pixel Colors...
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...
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.
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,
You need to use a binary mask to extract the nibble (4bits) that you want:
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
#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
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???
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???
quote:Original post by Asker
I don''t know if this is the right way, Is it???
Eternally useful advice: try it out.
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
Edited by - Asker on November 18, 2001 9:16:46 AM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement