19,469
社区成员
发帖
与我相关
我的任务
分享
BOOL CTwain::WriteDIB(LPTSTR szFile, HANDLE hDIB)
{
BITMAPFILEHEADER hdr;
LPBITMAPINFOHEADER lpbi;
if (!hDIB)
return FALSE;
CFile file;
if(!file.Open( szFile, CFile::modeWrite))
return FALSE;
lpbi = (LPBITMAPINFOHEADER)hDIB;
int nColors = 1 << lpbi->biBitCount;
// Fill in the fields of the file header
hdr.bfType = ((WORD) ('M' << 8) | 'B'); // is always "BM"
hdr.bfSize = GlobalSize (hDIB) + sizeof( hdr );
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;
hdr.bfOffBits = (DWORD) (sizeof( hdr ) + lpbi->biSize +
nColors * sizeof(RGBQUAD));
// Write the file header
file.Write( &hdr, sizeof(hdr) );
// Write the DIB header and the bits
int x=GlobalSize(hDIB);
file.Write(lpbi, GlobalSize(hDIB) ); //执行这句会出严重的错误,我传的参数是HBITMAP句柄,
//不知道会不会有问题 ,句柄有值,lpbi也是有效的,是不是lpbi指向的是一快无效的内存,所以会出错??
return TRUE;
}