我從庫中獲取一個字節數組,我想將它保存爲Tiff文件灰度/每像素16位。將圖像保存爲Tiff
我用這個方法來做到這一點:
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
}
而我得到的錯誤「一般錯誤在GDI +發生」。 在Vista/32位和Win7/64位上都會出現此問題。 我使用.NET 4.0
編輯:
如果我改變ImageFormat.Tiff
到ImageFormat.Bmp
我沒有錯誤。但它仍然是我想要的TIFF圖像。
您在哪一行收到錯誤?你能提供一些像素值字節嗎? – CodingBarfield 2012-03-06 14:33:55
其中一個原因 - 您沒有權限寫入目錄 – Reniuz 2012-03-06 14:36:50
字節是...字節。採取2乘2,他們正在編寫「ushort」的灰度。 – gregseth 2012-03-06 14:37:07