在 .NET 中提取有关 PNG 的图像信息
我正在尝试获取有关 PNG 文件的信息,但我还没有找到一个综合网站来帮助我。
这些是我拥有的一些半有用的代码片段:
Bitmap bmp = new Bitmap(pngFileName);
BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly,PixelFormat.Format48bppRgb);
通过
Stream imageStreamSource = new FileStream(pngFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
var decoder = new PngBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];
这些,我已经能够获取图像的高度和宽度。但是我仍然需要发现以下信息:
- 它是 RLE 编码的吗?
- 是原生视频格式吗?
- 是旋转的吗?
- 它使用灰度调色板吗?
- 它有透明度吗?
- 是RGB还是BGR?
我真的很感激一些关于如何实现这一目标的指示或链接到处理此问题的好文章。我们正在使用 .NET 4.0
I'm trying to get information about a PNG file but I've yet to discover a comprehensive site to help me.
These are some of the semi useful code snippets I have:
Bitmap bmp = new Bitmap(pngFileName);
BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly,PixelFormat.Format48bppRgb);
and
Stream imageStreamSource = new FileStream(pngFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
var decoder = new PngBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];
With these I've been able to to get the image height and width. However I still need to discover the following information:
- Is it RLE encoded?
- Is it in native video format?
- Is it rotated?
- Does it use a grayscale palette?
- Does it have a transparency?
- Is it RGB or BGR?
I'd really appreciate some pointers on how to acheive this or links to good articles dealing with this. We're working with .NET 4.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否对您有帮助,但迄今为止我所见过的最好的方法是在循环中逐像素地遍历图像并完成不同的任务。
请参阅以下答案以获取示例:
I'm not sure if that helps you, but the best I've seen so far, is to walk the image pixel by pixel in a loop and accomplish your different tasks.
See these answers for examples: