Find out png color type using png++
I'm using png++, which is working ok, but you need to set th开发者_运维技巧e 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.
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.
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.
精彩评论