Thursday, August 09, 2012 10:32 AM
I am working on image conversion mostly BMP to 16 bit,8 bit, and monochrome.
I just converted a BMP image(24 bit) to 16 bit image using following code
#define RGB16(red, green, blue) (((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3))
for( int y=0; y<infoheader.biHeight; ++y)
for( int x=0; x<infoheader.biWidth; ++x)
fread(&blue, sizeof(BYTE), 1, bitmapFile);
fread(&green, sizeof(BYTE), 1, bitmapFile);
fread(&red, sizeof(BYTE), 1,bitmapFile);
bitmapData[y*infoheader.biWidth + x] = RGB16(red, green, blue);
But the image i got in 16 bit differs from the same image converted to 16-color bit obtained using MS paint?????Why this is happening????
Also please explain me how to convert 24 bit BMP image to monochrome???????
Thursday, August 09, 2012 10:39 AM
A 16bit image has in total the possibility on using 65536 colors. A color value is represented by two bytes. A 16 color image has only 16 colors in total. A color value is repesented by 4 bits. Two pixels are stored in one byte. Therefore the images are not (binary) identical, even if the images loors the same in a picture viewer.
Here you can read about the different BMP image "sub"-types:
Addition:The Bitmaps with lower color number of colors also works with color tables. A pixel value does not represent the real color value, it only represents a table index in the color table.
Thursday, August 09, 2012 10:47 AM
Will you suggest me how can i convert 24 bit BMP image to Monochrome(1 bit )BMP image
Thursday, August 09, 2012 12:27 PM
In a monochrome bitmap 8 pixels are stored in a byte. To find out how to convert such bitmaps from i.e. 24bit to 1 bit I'd suggest checking the Bitmap file specifications thar running around in the internet. The Wikipedia link should help you to learn how the specific bitmpa types are organized and stored.
The difficuilt part on converting is that you still have a remeining picture information in your converted bitmap. There are algorithms out, but I can not actually point them out.
Here a few information about the windows bmp file format:
Also this article is very nice and explains how bitmaps work that use color tables: