把test程序给你:
UINT RGB256Table[256]={0};//初始化为空,需要从任何一个256色的bmp中读入
void WriteBMP()
{
BITMAPFILEHEADER bmpHead;
BITMAPINFOHEADER bmpInfoHead;
memset(&bmpHead,0,sizeof(bmpHead));
bmpHead.bfType=0x4D42;//BM
bmpHead.bfSize=sizeof(bmpHead)+sizeof(bmpInfoHead)+256*sizeof(RGBQUAD)+sizeof(Your_Bits);
bmpHead.bfOffBits=sizeof(bmpHead)+sizeof(bmpInfoHead)+256*sizeof(RGBQUAD);
//
memset(&bmpInfoHead,0,sizeof(BITMAPINFOHEADER));
bmpInfoHead.biSize=sizeof(BITMAPINFOHEADER);
bmpInfoHead.biPlanes=1;
bmpInfoHead.biBitCount=8;
bmpInfoHead.biCompression=BI_RLE8;
bmpInfoHead.biClrImportant=256;
bmpInfoHead.biClrUsed=256;
//
bmpInfoHead.biHeight=40;//就是你的h文件中的数据
bmpInfoHead.biWidth=40;
bmpInfoHead.biSizeImage=sizeof(Your_Bits);//即你的RLE8数据
//
FILE *bmp;
// read 256 color in 只读256色
bmp=fopen("256clr.bmp","rb");//any bmp has 256 colors
fseek(bmp,sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER),SEEK_SET);
fread(RGB256Table,sizeof(RGB256Table),1,bmp);
fclose(bmp);
//write new bmp
bmp=fopen("YourTest.bmp","wb");
fwrite(&bmpHead,sizeof(bmpHead),1,bmp);
fwrite(&bmpInfoHead,sizeof(bmpInfoHead),1,bmp);
fwrite(RGB256Table,sizeof(RGB256Table),1,bmp);
fwrite(Your_Bits,sizeof(Your_Bits),1,bmp);
fclose(bmp);
}
//正常时用paintbrush可以打开,可惜你的data又经过某种处理了。