Thanks, but for gdk-pixbuf-new-from-data I need to know size and properties of the original image… it’s an information that I find very difficult to obtain. Is there a simpler way?
About gdk-pixbuf-new-from-file, for some reasons the images are embedded, so i can’t use it. Regards, Ale ________________________________ From: Joël Krähemann <jkraehem...@gmail.com> Sent: Sunday, November 11, 2018 8:29:37 PM To: misterbi...@hotmail.it Cc: gtk-app-devel-. Subject: Re: Working with embedded images with GResource, GdkPixbuf and GtkWidget Hi, First you create a GdkPixbuf: https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-Image-Data-in-Memory.html#gdk-pixbuf-new-from-data then set the property of about dialog: https://developer.gnome.org/gtk2/stable/GtkAboutDialog.html#GtkAboutDialog--logo g_object_set(your_about_dialog, "logo", your_pixbuf, NULL); Why don't you use just following? https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-File-Loading.html#gdk-pixbuf-new-from-file Bests, Joël On Sun, Nov 11, 2018 at 6:23 PM Alessandro Francesconi <misterbi...@hotmail.it> wrote: > > Hello, > > > > I need to show some images inside my GTK+ 2.32 application so I decided to > embed them using GResource compiler. > > I’ve prepared an XML file like this: > > > > <?xml version="1.0" encoding="UTF-8"?> > > <gresources> > > <gresource prefix="/myapp/icons"> > > <file preprocess="to-pixdata">logo.png</file> > <…..> > > </gresource> > > </gresources> > > > > And after “glib-compile-resources.exe --target=icons.c --generate icons.xml”, > I correctly have a .c file with images encoded inside. > > > > Problem here: i need that images to be shown in About dialog > (gtk_show_about_dialog) and buttons (gtk_button_set_image). As far as I know, > to accomplish this I have to create GdkPixbuf (for gtk_about_dialog_set_logo) > and GtkWidget (for gtk_button_set_image). I tried with this code but got some > issues (see the comments): > > > > ----------- > > GResource* icons = icons_get_resource(); > > GBytes* data = g_resource_lookup_data(icons, path, > G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); > > gsite size = g_bytes_get_size(data); // <-- this works since I have no > errors and the size is > 0, so I expect data to be ok > > > > // now I need to create a GdkPixbuf, is that the correct way? > > GError* e = NULL; > > GdkPixbuf* pixbuf; > > pixbuf = gdk_pixbuf_new_from_inline(g_bytes_get_size(data), data, FALSE, > &e); > // error here! Message is “Image header corrupt” > > > > // if worked… I’d continue by also getting the GtkWidget image with: > GtkWidget* image; > > image = gtk_image_new_from_pixbuf(pixbuf); > > ----------- > > > > I can’t really understand how Pixbuf expects from the GResource data… also i > read in the docs that “gdk_pixbuf_new_from_inline has been deprecated since > version 2.32 and should not be used in newly-written code. Use GResource > instead.”… so what’s the correct way to create Pixbuf for About boxes and > GdkWidgets for image button? > > > > Thanks for the support > > Alessandro > > > > _______________________________________________ > gtk-app-devel-list mailing list > email@example.com > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list _______________________________________________ gtk-app-devel-list mailing list firstname.lastname@example.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list