Context
I'm new to Vala development (although I have some years of experience with C#) under Linux, and I decided to recreate one of my C# programs, however, I need to use images in the UI.
My problem
How can I embed resource files (such as images) for later use in the UI? How to access them later? And how to put them in a button?
What I'm using
I'm using Linux (Mint) and Anjuta development IDE, with the Glade UI designer integrated. The Vala project targets a GTK+ 3.0 project.
What I've tried
I have tried adding a new specific objective for images, adding them into the project... But I don't seem to succeed. I have seen the default images provided by Linux, and those work just fine, but I need to add my own.
Thanks in advance!
The normal approach would be to install your images to
PREFIX/share/pixmaps/YOUR_APP. For example Gnumeric installs some.pngfiles in/usr/share/pixmaps/gnumeric/.You can use
GResourceto embed binary files (like images) into your executable if you really want to. Theglib-compile-resourcescommand can be added to your build system (see also this question).You can also use icons from the users icon theme.
You didn't write what component you want to use to display your images, so I'll assume
Gtk.Imagehere.Gtk.Imagehas several constructors for the purpose of loading the image:GResource.See the main documentation of
Gtk.Imagefor more methods. Some other widgets have similar methods to load images (for example toolbar buttons).You should not use
from_stockany more (There was astocksystem in Gtk+ that is being replaced by freedesktop.org icon schemas).