Is it somehow possible to set the opacity of a of a GdkPixbuf
to about 50%? The thing is i am writing in Gtk2 (cannot switch to Gtk3!) a filebrowser widget (for a remote file transfer) and I want the icons of the files to be 50% transparent if the file is hidden.
I get the icon using GFileInfo
and load it into a GdkPixbuf
, but I do not know how to change the opacity.
Advertisement
Answer
Transparency is handled in the alpha channel. If your pixbuf isn’t transparent (check with gdk_pixbuf_get_has_alpha), you may try to call gdk_pixbuf_add_alpha to add the alpha channel. Then you iterate on the pixels and set the alpha value for each pixel to 50% (i.e. 128) as gdk-pixbuf uses unpremultiplied alpha. See the documentation for a way to iterate on the pixels.