Re: hello, Mr. Ronald Bultje

 do you have the scribble source codes in GTk tutorial?
I checked online but no source code available. :(
almost driven by the error, white window no image!


From: Ronald Bultje <rbultje ronald bitfreak net>
To: guo li <liguo503 hotmail com>
CC: gtk-list gnome org
Subject: Re: hello,  Mr. Ronald Bultje
Date: 16 Mar 2002 08:57:35 +0100


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,

/* place the image in the widget */
gdk_pixbuf_render_to_drawable (pixbuf, widget->window,
  widget->style->white_gc, 0, 0, 0, 0,

/* use general Gtk+-1.2 routines to add the widget to a
 * window and show it */
--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 */
--code ends here--



-   .-.
-   /V\    | Ronald Bultje <rbultje ronald bitfreak net>
-  // \\   | Running: Linux 2.4.18-XFS and OpenBSD 3.0
- /(   )\  |
-  ^^-^^

gtk-list mailing list
gtk-list gnome org

Get your FREE download of MSN Explorer at

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]