3×2的bitmap为什么无法预览?而8x1的却可以
无法预览,在windows画板中可以打开
代码是这样的:
//bitmap.cx = 3; bitmap.cy = 2
//strFileName = 3-2.bmp
long lBufferSize = bitmap.cx * bitmap.cy * 3;
HANDLE hf = CreateFile(strFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL,
CREATE_ALWAYS, NULL, NULL );
if( hf == INVALID_HANDLE_VALUE )
return;
// write out the file header
//
BITMAPFILEHEADER bfh;
memset( &bfh, 0, sizeof( bfh ) );
bfh.bfType = 'MB';
bfh.bfSize = sizeof( bfh ) + lBufferSize + sizeof( BITMAPINFOHEADER );
bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( BITMAPFILEHEADER );
DWORD dwWritten = 0;
WriteFile( hf, &bfh, sizeof( bfh ), &dwWritten, NULL );
// and the bitmap format
//
BITMAPINFOHEADER bih;
memset( &bih, 0, sizeof( bih ) );
bih.biSize = sizeof( bih );
bih.biWidth = bitmap.cx;
bih.biHeight = bitmap.cy;
bih.biPlanes = 1;
bih.biBitCount = 24;
dwWritten = 0;
WriteFile( hf, &bih, sizeof( bih ), &dwWritten, NULL );
// and the bits themselves
//
dwWritten = 0;
WriteFile( hf, pBuffer, lBufferSize, &dwWritten, NULL );
CloseHandle( hf );