RE: Working with embedded images with GResource, GdkPixbuf and GtkWidget
It works! I didn’t know about gdk_pixbuf_new_from_resource() thank you. Ale From: infirit Sent: Sunday, November 11, 2018 11:11:53 PM To: Alessandro Francesconi; gtk-app-devel-list@gnome.org Subject: Re: Working with embedded images with GResource, GdkPixbuf and GtkWidget Op 11-11-18 om 18:23 schreef Alessandro Francesconi: > 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? Never used GResource but.. The GdkPixbuf docs has gdk_pixbuf_new_from_resource() which will take the path to the pixdata in the GResource. The path based on your example probably is /myapp/icons/logo.png. ~infirit ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Working with embedded images with GResource, GdkPixbuf and GtkWidget
Op 11-11-18 om 18:23 schreef Alessandro Francesconi: 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? Never used GResource but.. The GdkPixbuf docs has gdk_pixbuf_new_from_resource() which will take the path to the pixdata in the GResource. The path based on your example probably is /myapp/icons/logo.png. ~infirit ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
RE: Working with embedded images with GResource, GdkPixbuf and GtkWidget
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 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 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: > > > > > > > > > > logo.png ><…..> > > > > > > > > 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 > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
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 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: > > > > > > > > > > logo.png ><…..> > > > > > > > > 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 > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list