使用 png++ 找出 png 颜色类型
我正在使用 png++,它工作正常,但是您需要将像素类型设置为模板参数:
png::image< png::rgb_pixel > image("input.png");
问题是我在编译时不知道它是否是 rgb、rgba 等。似乎找不到让 png++ 告诉我 png 中实际包含哪些信息的方法。
有什么想法吗?
谢谢。
I'm using png++, which is working ok, but you need to set the pixel type as a template parameter:
png::image< png::rgb_pixel > image("input.png");
The problem is I don't know at compile time whether it is rgb, rgba etc. Can't seem to find a way to get png++ to tell me what info is actually in the png.
Any ideas?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用阅读器。然后查看其基类 io_base 的成员函数。我认为它有你正在寻找的东西。
Try using a reader. Then check out the member functions of it's base class, io_base. I think it has what you're looking for.
嘿,
png++
的作者来帮忙:)如果您确实需要知道 PNG 图像中的像素格式是什么,那么使用
png::reader
是受支持的方式:但是,如果您不关心图像颜色类型而只想将其加载到例如 RGBA 缓冲区中,我建议使用
png::image< rgba_pixel > image("input.png")
:这会自动将任何颜色类型的 PNG 图像转换为 RGBA。Hey, author of
png++
here to help :)If you really need to know what pixel format is in the PNG image, using
png::reader
is the supported way:However, if you don't care of the image color type and just want to load it into, e.g. RGBA buffer, I'd suggest using
png::image< rgba_pixel > image("input.png")
: this will automagically convert PNG image of any color type to RGBA for you.