c++ - Pixbuf 显示有关图像的错误信息

标签 c++ image user-interface gtk gtkmm

无论我将什么图片加载到 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/

相关文章:

c++ - Visual Studio 2017 是否完全支持具有 [[deprecated]] 属性的 N4266?

python - 使用 skimage 旋转图像而不裁剪它

python - 如何从 3d numpy 数组(28X28 行)中删除其他 3d numpy 数组(Python)中存在的所有行?

python - wxPython如何设置状态栏中小部件的位置

c++ - 如何在多集中打印值?

c++ - 将静态库封装在动态链接库 (DLL) 中

c++ - boost 链接错误

html - 调整图像大小以适应具有最大宽度集的 div

java - 如何通过键盘输入滚动面板?JAVA

function - AHK V2 如何在按钮的单击事件上调用函数