Pixbuf shows wrong info about image
No matter what picture I load into Gdk::Pixbuf (using GTKmm) it always shows the same info. I'm taking about functions get_n_channels(), get_bits_per_sample() and get_has_alpha().
I check images by others programs and they shows different (but correct) information. Help!
Some of my code:
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
Note that GdkPixbuf supports a very limited set of pixel formats:
- RGB color, 8 bits per channel
- 8-bit alpha channel, or no alpha at all
When you load an image with GdkPixbuf, it converts the image to 24-bit RGB, plus 8-bit alpha if the image had transparency. For example, if you load a grayscale image, it will get "exploded" to RGB channels. That's why you only ever get GDK_COLORSPACE_RGB out of gdk_pixbuf_get_colorspace(), and 8 out of _get_bits_per_sample().
This is suboptimal, but we only had time to implement that when we were initially writing GdkPixbuf. IrfanView will of course have a more sophisticated idea of image representations - it will show you what the original image file declares, not the internal representation that the image has when it gets decoded.