void saveFile(LPBYTE lpBits,int nWidth,int nHeight, CString strPath)
{
BITMAPFILEHEADER bmpFileHdr;
BITMAPINFOHEADER bmpInfoHdr;
RGBQUAD rgbQuad[256];
memset(&bmpFileHdr,0,sizeof(BITMAPFILEHEADER));
memset(&bmpInfoHdr,0,sizeof(BITMAPINFOHEADER));
bmpFileHdr.bfType=19778;
bmpFileHdr.bfOffBits=1078;
bmpFileHdr.bfSize=1078+nWidth*nHeight;
bmpInfoHdr.biSize=sizeof(BITMAPINFOHEADER);
bmpInfoHdr.biWidth=nWidth;
bmpInfoHdr.biHeight=nHeight;
bmpInfoHdr.biPlanes=1;
bmpInfoHdr.biBitCount=8;
bmpInfoHdr.biSizeImage=nWidth*nHeight;
bmpInfoHdr.biClrUsed=256;
for(int i=0;i<256;i++)
{
rgbQuad[i].rgbBlue=rgbQuad[i].rgbGreen=rgbQuad[i].rgbRed=i;
rgbQuad[i].rgbReserved=0;
}
FILE* fp=fopen(strPath,"wb");
ASSERT(fp);
fwrite(&bmpFileHdr,1,sizeof(BITMAPFILEHEADER),fp);
fwrite(&bmpInfoHdr,1,sizeof(BITMAPINFOHEADER),fp);
fwrite(rgbQuad,sizeof(RGBQUAD),256,fp);
fwrite(lpBits,1,nHeight*nWidth,fp);
fclose(fp);
}
保存图像
最新推荐文章于 2018-06-13 08:33:45 发布