I have a C code which create bitmap like this.
long SaveBmpFile( LPCTSTR filename, BYTE *ImageBitmap, DWORD BitmapByteCount, long width, long height)
{
FILE *fp;
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
DWORD dwBitmapByteCountPerLine;
DWORD dwBitmapByteCount;
dwBitmapByteCountPerLine = (width * 3 + 3) & (~3);
// Windows Bitmap requires each line to be 32bits boundary
dwBitmapByteCount = height * dwBitmapByteCountPerLine;
bfh.bfType = 0x4d42;
bfh.bfSize = BitmapByteCount + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0;
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bih.biSize = sizeof (BITMAPINFOHEADER);
bih.biWidth = width;
bih.biHeight = height;
bih.biPlanes = 1;
bih.biBitCount = 24;
bih.biCompression = BI_RGB;
bih.biSizeImage = 0;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
bih.biClrUsed = 0;
bih.biClrImportant = 0;
fp = fopen (filename, "wb");
if (! fp)
{
return -1;
}
// make Bitmap data
BYTE *bp = ImageBitmap;
fwrite (&bfh.bfType, 1, sizeof(BITMAPFILEHEADER), fp);
fwrite (&bih.biSize, 1, sizeof(BITMAPINFOHEADER), fp);
fwrite (bp, 1, dwBitmapByteCount, fp);
fclose (fp);
return 0;
}
Is there BITMAPFILEHEADER equivalent class of C#? or define by myself?
long SaveBmpFile( LPCTSTR filename, BYTE *ImageBitmap, DWORD BitmapByteCount, long width, long height)
{
FILE *fp;
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
DWORD dwBitmapByteCountPerLine;
DWORD dwBitmapByteCount;
dwBitmapByteCountPerLine = (width * 3 + 3) & (~3);
// Windows Bitmap requires each line to be 32bits boundary
dwBitmapByteCount = height * dwBitmapByteCountPerLine;
bfh.bfType = 0x4d42;
bfh.bfSize = BitmapByteCount + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0;
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bih.biSize = sizeof (BITMAPINFOHEADER);
bih.biWidth = width;
bih.biHeight = height;
bih.biPlanes = 1;
bih.biBitCount = 24;
bih.biCompression = BI_RGB;
bih.biSizeImage = 0;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
bih.biClrUsed = 0;
bih.biClrImportant = 0;
fp = fopen (filename, "wb");
if (! fp)
{
return -1;
}
// make Bitmap data
BYTE *bp = ImageBitmap;
fwrite (&bfh.bfType, 1, sizeof(BITMAPFILEHEADER), fp);
fwrite (&bih.biSize, 1, sizeof(BITMAPINFOHEADER), fp);
fwrite (bp, 1, dwBitmapByteCount, fp);
fclose (fp);
return 0;
}
Is there BITMAPFILEHEADER equivalent class of C#? or define by myself?