I've inherited a C# .Net Windows Forms project which receives a Device Independent Bitmap (as an array of bytes) from a Managed pre-compiled DLL. The C# code makes a dummy BMP file from the DIB so that it can create a Bitmap which can then be drawn using System.Drawing.Graphics.DrawImage.
using (MemoryStream ms = new MemoryStream())
{
ms.Write(fileHeader, 0, fileHeader.Length);
ms.Write(dibBuffer, 0, dibBuffer.Length);
Bitmap img = (Bitmap)Image.FromStream(ms);
g.DrawImage(img, 0, 0, width, height);
}
This works when the DIB contains uncompressed pixel data but on some hardware, the pixel data is in YV12 format and Image.FromStream raises a System.ArgumentException which I think indicates that the underlying code (GDI+?) considers the BMP to be in an invalid or unsupported format.
In this scenario, the DIB's BITMAPINFOHEADER (first 40 bytes) has these values:
biSize: 40
biWidth:640
biHeight: 480
biPlanes: 1
biBitCount: 12
biCompression: 'YV12'
biSizeImage: 460800
biXPelsPerMeter: 0
biYPelsPerMeter: 0
biClrUsed: 0
biClrImportant: 0
Does the BMP format even support YV12? I can't find any example images online.
Is there a different way of handling the DIB to make it suitable for DrawImage? The above code seems to jump through hoops.