【发布时间】:2010-09-25 22:19:21
【问题描述】:
我正在尝试编写一个将每像素 48 位 PNG 文件转换为专有 (Bayer) 格式的应用程序。
下面的代码(由 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));
}
}
【问题讨论】:
-
也许您想告诉我们异常的文本?