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