VC怎样把一副自己画的图存成BMP格式

发表于:2007-07-14来源:作者:点击数: 标签:
int SaveBmp(HANDLE hData,LPSTR filename) { BITMAPFILEHEADER bfh; BITMAPINFOHEADER *lpbi=(BITMAPINFOHEADER*)hData; bfh.bfType=0x4D42; //BM bfh.bfSize=sizeof(bfh)+GlobalSize(hData); bfh.bfReserved1=bfh.bfReserved2=0; int colors=1biBitCount;
int SaveBmp(HANDLE hData,LPSTR filename)
{
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER *lpbi=(BITMAPINFOHEADER*)hData;

bfh.bfType=0x4D42; //BM
bfh.bfSize=sizeof(bfh)+GlobalSize(hData);
bfh.bfReserved1=bfh.bfReserved2=0;
int colors=1<biBitCount;
if(colors>256) colors=0;
bfh.bfOffBits=sizeof(bfh)+lpbi->biSize+colors*sizeof(RGBQUAD);

HANDLE hFile=CreateFile(filename,GENERIC_WRITE
,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile)
{
DWORD write;
WriteFile(hFile,&bfh,sizeof(bfh),&write,NULL);
WriteFile(hFile,lpbi,GlobalSize(hData),&write,NULL);
int i=sizeof(hData);
CloseHandle(hFile);
return true;
}
return false;
}

原文转自:http://www.ltesting.net