How to use GdkPixBuf?
I want to display a simple GIF image in a VBox using GTK+ from C. I know that I need to use a GdkPixbuf. But as usual there are no example of doing it. Can anyone provide help?
Also: In GTK+ how can we add a PNG image as background to a widget? Can anyone provide an example?
Forgot something to add this:
forgot to tell u that i am using Glade to develop GUI... And i have created vBox in Glade and in one of the blocks of the vBox i need to display FIG开发者_StackOverflow中文版 Image.... Sorry of this...
gdk_pixbuf_new_from_file()
-- but see unwind's answer for a better way to do it using aGtkImage
widget.You need to set the background pixmap field in the widget's style structure:
GtkRcStyle *newstyle = gtk_widget_get_modifier_style(widget); newstyle->bg_pixmap_name[GTK_STATE_NORMAL] = g_strdup(pngfilename); gtk_widget_modify_style(widget, newstyle);
PS. You can often find code examples by doing a Google search for the function you need an example of. The GTK docs usually don't contain examples for every single function, because that would clutter them up, and the documentation of functions like gdk_pixbuf_new_from_file()
is usually pretty straightforward. I've noticed you often post this kind of question and I'm wondering if you are looking for the documentation in the right place. For example, are you using the excellent reference tool DevHelp? On the other hand, the GTK documentation is really missing some important information in a few places. If you have some improvements, why not contribute to the documentation?
A vbox in GTK+ is a widget, that displays other widgets as its children, stacking them vertically.
Unsurprisingly, there is a GTK+ widget dedicated to displaying images; it's called GtkImage. You should use the gtk_image_new_from_file()
call to create one, passing it your GIF filename, and then just add that to your vbox. There's no need to create the underlying GDK image yourself.
精彩评论