使用 png++ 找出 png 颜色类型

发布于 2024-10-13 01:20:03 字数 223 浏览 7 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事↓在人 2024-10-20 01:20:37

尝试使用阅读器。然后查看其基类 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.

少跟Wǒ拽 2024-10-20 01:20:32

嘿,png++ 的作者来帮忙:)

如果您确实需要知道 PNG 图像中的像素格式是什么,那么使用 png::reader 是受支持的方式:

png::reader< std::istream > reader(my_stream);
reader.read_info();
png::color_type color_type = reader.get_color_type();

但是,如果您不关心图像颜色类型而只想将其加载到例如 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:

png::reader< std::istream > reader(my_stream);
reader.read_info();
png::color_type color_type = reader.get_color_type();

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文