Mubeen Ahmed
July 31st, 1999, 10:54 AM
Hello
i want to decode the bits information in a *.bmp file , only the bit , iwant to delete the color table and extension info. etc
thanks
pherweg
July 31st, 1999, 04:28 PM
Hi,
hope this code helps. I didn't test it and there is no error
handling. But it shows how to do it.
First read the BITMAPFILEHEADER. Then read BITMAPINFO. Finaly the
bits.
Please write a short answer, if you have success.
Good luck!
Peter
FILE *f;
BITMAPFILEHEADER bmpfh;
BITMAPINFO *bmpinfo=NULL;
void *bits=NULL;
long infosize,bitsize,widthbyte;
// open file
f=fopen("test.bmp","rb");
// read the BITMAPFILEHEADER and calculate size of BITMAPINFO
fread((void*)&bmpfh,1,sizeof(BITMAPFILEHEADER),f);
infosize=bmpfh.bfOffBits-sizeof(BITMAPFILEHEADER);
// read BITMAPINFO
bmpinfo=(BITMAPINFO*)malloc(infosize));
fread((void*)bmpinfo,1,infosize,f);
if(bmpinfo->bmiHeader.biSizeImage==0)
{
widthbyte=(bmpinfo->bmiHeader.biWidth
*bmpinfo->bmiHeader.biBitCount+7)/8;
while(widthbyte%4) ++widthbyte;
bitsize=widthbyte*bmpinfo->bmiHeader.biHeight;
}
else
{
bitsize=bmpinfo->bmiHeader.biSizeImage;
}
// read bits
bits=malloc(bitsize);
fread(bits,1,bitsize,f);
// close file
fclose(f);