题
我试着写的应用程序转换为48位素PNG文件的专有的(拜耳公司)的格式。
代码(礼貌 在这里,)下的伟大工程,对于一些PNG文件的格式,但是,当我试着一个真正的48位新代码引发一个例外是否有一个选择吗?
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));
}
}
解决方案
BMP编码不支持48bpp格式。你可以得到一个分裂的象素与位图。LockBits()方法。虽然MSDN Library文PixelFormat说,48bpp是像对待24bpp的图像,我确实看到6字节的像素与这个代号:
Bitmap bmp = new Bitmap(@"c:\temp\48bpp.png");
BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
ImageLockMode.ReadOnly, PixelFormat.Format48bppRgb);
// Party with bd.Scan0
//...
bmp.UnlockBits(bd);
不隶属于 StackOverflow