I'm getting a byte array from a library and I want to save it as a Tiff file grayscale / 16-bit per pixel.
I'm using this method to do so:
private static void CreateBitmapFromBytes(byte[] pixelValues)
{
Bitmap pic = new Bitmap(1024, 1024, PixelFormat.Format16bppGrayScale);
BitmapData picData = pic.LockBits
( new Rectangle(0, 0, pic.Width, pic.Height)
, ImageLockMode.ReadWrite
, pic.PixelFormat
);
IntPtr pixelStartAddress = picData.Scan0;
Marshal.Copy(pixelValues, 0, pixelStartAddress, pixelValues.Length);
pic.UnlockBits(picData);
pic.Save("grid.tif", ImageFormat.Tiff); //< HERE IS THE ERROR
}
And I get the error "A generic error occurred in GDI+". The problem occurs both on Vista/32-bit and Win7/64-bit. I'm using .NET 4.0
EDIT:
If I change ImageFormat.Tiff to ImageFormat.Bmp I don't have the error. But it's still a TIFF image that I want.
ushorts. - gregseth