Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

GtkImage is a GTK 4 widget for displaying image content, especially fixed-size items such as icons. It can show files, icon names, GIcons, paintables, and resources. For an image you want displayed at its natural size, GTK’s guidance points to GtkPicture instead.

What GtkImage does

GtkImage displays image content inside a GTK interface. Its constructors and setters support several kinds of content, including a file, an icon name, a GIcon, a GdkPaintable, and a resource. See the GTK 4 GtkImage class reference for the class API.

The choice of content type determines which constructor is appropriate. Common GTK 4 constructors include gtk_image_new_from_file(), gtk_image_new_from_icon_name(), gtk_image_new_from_gicon(), gtk_image_new_from_paintable(), and gtk_image_new_from_resource(). The class reference also lists a pixbuf constructor, but GTK’s migration guide marks GtkImage’s pixbuf-specific APIs deprecated since GTK 4.12. For new code, use the API that matches your content and check compatibility with the GTK version you target.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

GtkImage or GtkPicture?

GTK 4 separates the jobs that GtkImage and GtkPicture handle. Use GtkImage for fixed-size content such as icons; use GtkPicture when you want to display a paintable at its natural size. These are practical defaults from GTK’s documentation, not a complete comparison of every layout or rendering behavior.

Widget Best-fit use Content model
GtkImage Fixed-size images, particularly icons Supports image representations such as named icons, files, resources, and paintables
GtkPicture Images displayed at natural size Displays a GdkPaintable, with convenience APIs for files and resources

This division reflects GTK 3-to-4 migration guidance: GtkPicture’s behavior was split out of GtkImage, while GtkImage remains useful for icons. Read the GTK 3-to-4 migration guide and GtkPicture class reference when choosing for a particular interface.

How to display an image from a file

In GTK 4, create an image widget from a file with gtk_image_new_from_file(), passing the file path. The constructor returns a widget even if the file is missing or cannot be loaded; in that case, GtkImage displays a broken-image icon. It does not signal a load failure by returning NULL.

If the application must detect a failed load and present its own error UI, GTK’s reference recommends loading the image through an image framework such as libglycin first, then creating GtkImage from the resulting texture. The GtkImage file-constructor reference describes the failure behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Displaying paintables and tracking changes

A GdkPaintable can represent content that changes over time. When you pass one to gtk_image_new_from_paintable(), GtkImage tracks it: changes to the paintable update the widget’s displayed contents and size. The GtkImage icon-size setting also affects paintables, so use GtkPicture if natural-size display is the goal. See the paintable constructor reference.

The paintable property is the currently displayed GdkPaintable. gtk_image_get_paintable() returns that object or NULL; the returned object is owned by the GtkImage instance, so callers should not treat the result as an owned reference. The paintable property and getter reference document these details.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Using themed and symbolic icons

For an icon supplied by name, GtkImage’s icon-name API is the straightforward option. GTK’s migration guide notes a specific consideration when using GtkIconTheme to look up an icon and passing the resulting GtkIconPaintable directly: a symbolic icon supplied this way is not automatically recolored according to the rendering context. If you want the theme’s symbolic palette behavior, use the icon name on GtkImage. Because this is migration-specific guidance, verify the behavior against the GTK version your application targets.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.