Hi, On Sat, 2002-03-16 at 04:53, guo li wrote: > Hi, Mr Ronald Bultje, > I am now having a headache with displaying a jpeg picture using GTK, > can you please send me the code you mentioned in the following: > your help will be greatly appreciated.
Here's the code I use in gtk+-1.2: --code for gtk+-1.2 starts here-- char *file = "/path/to/file.jpg"; /* this can be any widget as long as it has its own * GdkWindow for example, use a GtkDrawingArea or a * GtkEventBox */ GtkWidget *widget; GdkPixbuf *pixbuf; /* create the widget and the pixbuf */ widget = gtk_event_box_new(); /* could be any widget */ pixbuf = gdk_pixbuf_new_from_file(file); /* resize the widget so that the pixbuf fits */ gtk_widget_set_usize(widget, gdk_pixbuf_get_width(pixbuf, gdk_pixbuf_get_height(pixbuf)); /* place the image in the widget */ gdk_pixbuf_render_to_drawable (pixbuf, widget->window, widget->style->white_gc, 0, 0, 0, 0, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), GDK_RGB_DITHER_NORMAL, 0, 0); /* use general Gtk+-1.2 routines to add the widget to a * window and show it */ [..] gtk_widget_show(widget); --code ends here-- And here's my way of doing it in gtk+-2.0: --code for gtk+-2.0 starts here-- char *file = "/path/to/file.jpg"; GtkWidget* image; GdkPixbuf *pixbuf; /* reate the image widget */ pixbuf = gdk_pixbuf_new_from_file(file); image = gtk_image_new_from_pixbuf(pixbuf); /* attach gtkimage widget to a parent and show it */ [..] gtk_widget_show(image); --code ends here-- Goodluck, Ronald -- - .-. - /V\ | Ronald Bultje <[EMAIL PROTECTED]> - // \\ | Running: Linux 2.4.18-XFS and OpenBSD 3.0 - /( )\ | http://ronald.bitfreak.net/ - ^^-^^ _______________________________________________ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list