Re: GdkPixbuf object from stock icons



On Sat, Sep 22, 2007 at 03:17:51PM +0300, Zeeshan Ali wrote:
  I was looking for a non-hackish way of creating a GdkPixbuf object
out of stock icon. The first thing that comes to mind is:

------------------CODE SNIPPET BEGIN----------------------

image = gtk_image_new_from_stock (stock_id, size);
pixbuf = gtk_image_get_pixbuf (image);

------------------CODE SNIPPET END-------------------------

 However that doesn't work since the created image if of storage type
GTK_IMAGE_STOCK and gtk_image_get_pixbuf() doesn't like that.

Yes, the image is not backed by a pixbuf therefore it cannot
return it (a GtkImage method to render the image to a pixbuf
whatever it is backed with could be perhaps written, but it
would be something different).

Following is the only way i could come up with:

------------------CODE SNIPPET BEGIN----------------------

image = gtk_image_new ();
pixbuf = gtk_widget_render_icon (image, stock_id, size, NULL);

------------------CODE SNIPPET END-------------------------

   This one works quite fine but is obviously hackish, Does anyone
know of any better way of doing the same?

Not so obviously.  The primary difficulty is that your
problem is ill-posed.  The stock icon look is affected by
theme, state and whatnot.  It can even differ for different
widgets.

So depending on your preferred amount of manual work you
have the choice of

  gtk_widget_render_icon()
  gtk_icon_set_render_icon()
  gtk_style_render_icon()

The most raw method is

  gtk_icon_theme_lookup_icon() +  gtk_icon_info_load_icon()

However, the icon will probably end up rendered on some
widget -- and then use gtk_widget_render_icon() for this
widget.

Yeti

--
http://gwyddion.net/



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