The `GtkImage` widget displays an image.
![An example GtkImage](image.png)
Various kinds of object can be displayed as an image; most typically, you would load a `GdkTexture` from a file, using the convenience
function [[email protected]_from_file], for instance:
```c GtkWidget *image = gtk_image_new_from_file ("myfile.png"); ```
If the file isn’t loaded successfully, the image will contain a “broken image” icon similar to that used in many web browsers.
If you want to handle errors in loading the file yourself, for example by displaying an error message, then load the image with [
[email protected]_from_file], then create the `GtkImage` with [[email protected]_from_paintable].
Sometimes an application will want to avoid depending on external data files, such as image files. See the documentation of `GResource`
inside GIO, for details. In this case, [[email protected]:resource], [[email protected]_from_resource], and [
[email protected]_from_resource] should be used.
`GtkImage` displays its image as an icon, with a size that is determined by the application. See [[email protected]] if you want to show
an image at is actual size.
CSS nodes
`GtkImage` has a single CSS node with the name `image`. The style classes `.normal-icons` or `.large-icons` may appear, depending on the
[[email protected]:icon-size] property.
Accessibility
`GtkImage` uses the `GTK_ACCESSIBLE_ROLE_IMG` role.
- public void clear ()
Resets the image to be empty.
- public unowned Icon? get_gicon ()
Gets the `GIcon` being displayed by the `GtkImage`.
- public unowned string? get_icon_name ()
Gets the icon name and size being displayed by the `GtkImage`.
- public IconSize get_icon_size ()
Gets the icon size used by the this
when rendering icons.
- public unowned Paintable? get_paintable ()
Gets the image `GdkPaintable` being displayed by the `GtkImage`.
- public int get_pixel_size ()
Gets the pixel size used for named icons.
- public ImageType get_storage_type ()
Gets the type of representation being used by the `GtkImage` to store
image data.
- public void set_from_file (string? filename)
Sets a `GtkImage` to show a file.
- public void set_from_gicon (Icon icon)
Sets a `GtkImage` to show a `GIcon`.
- public void set_from_icon_name (string? icon_name)
Sets a `GtkImage` to show a named icon.
- public void set_from_paintable (Paintable? paintable)
Sets a `GtkImage` to show a `GdkPaintable`.
- public void set_from_pixbuf (Pixbuf? pixbuf)
Sets a `GtkImage` to show a `GdkPixbuf`.
- public void set_from_resource (string? resource_path)
Sets a `GtkImage` to show a resource.
- public void set_icon_size (IconSize icon_size)
Suggests an icon size to the theme for named icons.
- public void set_pixel_size (int pixel_size)
Sets the pixel size to use for named icons.