1
我正在嘗試編寫一個將每像素48位PNG文件轉換爲專有(拜耳)格式的應用程序。我如何查看'原始'PNG圖像數據
下面的代碼(禮貌here)適用於某些PNG文件格式,但是當我嘗試一個真正的48位PNG時,代碼會拋出異常 - 是否有替代方法?
static public byte[] BitmapDataFromBitmap(Bitmap objBitmap)
{
MemoryStream ms = new MemoryStream();
objBitmap.Save(ms, ImageFormat.BMP); // GDI+ exception thrown for > 32 bpp
return (ms.GetBuffer());
}
private void Bayer_Click(object sender, EventArgs e)
{
if (this.pictureName != null)
{
Bitmap bmp = new Bitmap(this.pictureName);
byte[] bmp_raw = BitmapDataFromBitmap(bmp);
int bpp = BitConverter.ToInt32(bmp_raw, 28); // 28 - BMP header defn.
MessageBox.Show(string.Format("Bits per pixel = {0}", bpp));
}
}
也許你想告訴我們異常的文本? – 2008-12-08 20:23:22