我如何查看“原始”? PNG图像数据
我正在尝试编写一个应用程序,将 48 位每像素 PNG 文件转换为专有(拜耳)格式。
下面的代码(由此处提供)效果很好对于某些 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));
}
}
I'm trying to write an application that converts 48 bit-per-pixel PNG files to a proprietary (Bayer) format.
The code (courtesy here) below works great for some PNG file formats, but when I try a bona fide 48 bit PNG the code throws an exception - is there an alternative?
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));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
BMP 编码器不支持 48bpp 格式。 您可以使用 Bitmap.LockBits() 方法来破解像素。 尽管 PixelFormat 的 MSDN 库文章说 48bpp 被视为 24bpp 图像,但实际上我确实使用以下代码看到了 6 字节像素:
The BMP encoder doesn't support 48bpp formats. You can get a crack at the pixels with the Bitmap.LockBits() method. Although the MSDN Library article for PixelFormat says that 48bpp is treated like 24bpp images, I do in fact see 6 byte pixels with this code: