无论我将什么图片加载到 Gdk::Pixbuf(使用 GTKmm),它总是显示相同的信息。我正在使用函数 get_n_channels()、get_bits_per_sample() 和 get_has_alpha()。
我检查其他程序的图像,它们显示不同(但正确)的信息。帮助!
我的一些代码:
Glib::RefPtr<Gdk::Pixbuf> ob = scene.get_pixbuf(); // some image
stringstream out;
out.str("");
out << ob->get_n_channels();
tekst +="Nr. of channels: <b>" + out.str() +"</b>\n";
out.str("");
out << ob->get_bits_per_sample();
tekst +="bits per sample: <b>" + out.str() +"</b>\n";
tekst +="alpha canal: <b>";
if (ob->get_has_alpha())tekst +="yes</b>\n";
else tekst +="no</b>\n";
info.set_markup(tekst); // Gtk::Label
最佳答案
请注意,GdkPixbuf 支持非常有限的一组像素格式:
- RGB 颜色,每 channel 8 位
- 8 位 alpha channel ,或者根本没有 alpha
当您使用 GdkPixbuf 加载图像时,它将图像转换为 24 位 RGB,如果图像具有透明度,则加上 8 位 alpha。例如,如果您加载灰度图像,它将“分解”为 RGB channel 。这就是为什么您只能从 gdk_pixbuf_get_colorspace() 中获取 GDK_COLORSPACE_RGB,而从 _get_bits_per_sample() 中获取 8 个。
这是次优的,但我们只有在最初编写 GdkPixbuf 时才有时间实现那个。 IrfanView 当然会对图像表示有更复杂的想法 - 它会向您显示原始图像文件声明的内容,而不是图像在解码时所具有的内部表示。
关于c++ - Pixbuf 显示有关图像的错误信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8057094/