Re: hello, Mr. Ronald Bultje



Hi,everyone,
 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!

:(
guo


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

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 <rbultje ronald bitfreak net>
-  // \\   | Running: Linux 2.4.18-XFS and OpenBSD 3.0
- /(   )\  | http://ronald.bitfreak.net/
-  ^^-^^

_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list




_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.




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