Class Image

All Implemented Interfaces:
PointerInterface

public class Image extends Widget
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
[ctor@Gtk.Image.new_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
[ctor@Gdk.Texture.new_from_file], then create the `GtkImage` with
[ctor@Gtk.Image.new_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, [property@Gtk.Image:resource],
[ctor@Gtk.Image.new_from_resource], and [method@Gtk.Image.set_from_resource]
should be used.

`GtkImage` displays its image as an icon, with a size that is determined
by the application. See [class@Gtk.Picture] 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
[property@Gtk.Image:icon-size] property.

## Accessibility

`GtkImage` uses the `GTK_ACCESSIBLE_ROLE_IMG` role.

https://docs.gtk.org/gtk4/class.Image.html

  • Constructor Details

    • Image

      public Image(PointerContainer pointer)
    • Image

      public Image()
      Creates a new empty `GtkImage` widget.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • newFromFileImage

      public static Image newFromFileImage(@Nonnull Str filename)
      Creates a new `GtkImage` displaying the file @filename.

      If the file isn’t found or can’t be loaded, the resulting `GtkImage`
      will display a “broken image” icon. This function never returns %NULL,
      it always returns a valid `GtkImage` widget.

      If you need to detect failures to load the file, use
      [ctor@Gdk.Texture.new_from_file] to load the file yourself,
      then create the `GtkImage` from the texture.

      The storage type (see [method@Gtk.Image.get_storage_type])
      of the returned image is not defined, it will be whatever
      is appropriate for displaying the file.
      Parameters:
      filename - a filename
      Returns:
      a new `GtkImage`
    • newFromFileImage

      public static Image newFromFileImage(String filename)
      Creates a new `GtkImage` displaying the file @filename.

      If the file isn’t found or can’t be loaded, the resulting `GtkImage`
      will display a “broken image” icon. This function never returns %NULL,
      it always returns a valid `GtkImage` widget.

      If you need to detect failures to load the file, use
      [ctor@Gdk.Texture.new_from_file] to load the file yourself,
      then create the `GtkImage` from the texture.

      The storage type (see [method@Gtk.Image.get_storage_type])
      of the returned image is not defined, it will be whatever
      is appropriate for displaying the file.
      Parameters:
      filename - a filename
      Returns:
      a new `GtkImage`
    • newFromGiconImage

      public static Image newFromGiconImage(@Nonnull Icon icon)
      Creates a `GtkImage` displaying an icon from the current icon theme.

      If the icon name isn’t known, a “broken image” icon will be
      displayed instead. If the current icon theme is changed, the icon
      will be updated appropriately.
      Parameters:
      icon - an icon
      Returns:
      a new `GtkImage` displaying the themed icon
    • newFromIconNameImage

      public static Image newFromIconNameImage(@Nullable Str icon_name)
      Creates a `GtkImage` displaying an icon from the current icon theme.

      If the icon name isn’t known, a “broken image” icon will be
      displayed instead. If the current icon theme is changed, the icon
      will be updated appropriately.
      Parameters:
      icon_name - an icon name
      Returns:
      a new `GtkImage` displaying the themed icon
    • newFromIconNameImage

      public static Image newFromIconNameImage(String icon_name)
      Creates a `GtkImage` displaying an icon from the current icon theme.

      If the icon name isn’t known, a “broken image” icon will be
      displayed instead. If the current icon theme is changed, the icon
      will be updated appropriately.
      Parameters:
      icon_name - an icon name
      Returns:
      a new `GtkImage` displaying the themed icon
    • newFromPaintableImage

      public static Image newFromPaintableImage(@Nullable Paintable paintable)
      Creates a new `GtkImage` displaying @paintable.

      The `GtkImage` does not assume a reference to the paintable; you still
      need to unref it if you own references. `GtkImage` will add its own
      reference rather than adopting yours.

      The `GtkImage` will track changes to the @paintable and update
      its size and contents in response to it.
      Parameters:
      paintable - a `GdkPaintable`
      Returns:
      a new `GtkImage`
    • newFromPixbufImage

      public static Image newFromPixbufImage(@Nullable Pixbuf pixbuf)
      Creates a new `GtkImage` displaying @pixbuf.

      The `GtkImage` does not assume a reference to the pixbuf; you still
      need to unref it if you own references. `GtkImage` will add its own
      reference rather than adopting yours.

      This is a helper for [ctor@Gtk.Image.new_from_paintable], and you can't
      get back the exact pixbuf once this is called, only a texture.

      Note that this function just creates an `GtkImage` from the pixbuf.
      The `GtkImage` created will not react to state changes. Should you
      want that, you should use [ctor@Gtk.Image.new_from_icon_name].
      Parameters:
      pixbuf - a `GdkPixbuf`
      Returns:
      a new `GtkImage`
    • newFromResourceImage

      public static Image newFromResourceImage(@Nonnull Str resource_path)
      Creates a new `GtkImage` displaying the resource file @resource_path.

      If the file isn’t found or can’t be loaded, the resulting `GtkImage` will
      display a “broken image” icon. This function never returns %NULL,
      it always returns a valid `GtkImage` widget.

      If you need to detect failures to load the file, use
      [ctor@GdkPixbuf.Pixbuf.new_from_file] to load the file yourself,
      then create the `GtkImage` from the pixbuf.

      The storage type (see [method@Gtk.Image.get_storage_type]) of
      the returned image is not defined, it will be whatever is
      appropriate for displaying the file.
      Parameters:
      resource_path - a resource path
      Returns:
      a new `GtkImage`
    • newFromResourceImage

      public static Image newFromResourceImage(String resource_path)
      Creates a new `GtkImage` displaying the resource file @resource_path.

      If the file isn’t found or can’t be loaded, the resulting `GtkImage` will
      display a “broken image” icon. This function never returns %NULL,
      it always returns a valid `GtkImage` widget.

      If you need to detect failures to load the file, use
      [ctor@GdkPixbuf.Pixbuf.new_from_file] to load the file yourself,
      then create the `GtkImage` from the pixbuf.

      The storage type (see [method@Gtk.Image.get_storage_type]) of
      the returned image is not defined, it will be whatever is
      appropriate for displaying the file.
      Parameters:
      resource_path - a resource path
      Returns:
      a new `GtkImage`
    • clear

      public void clear()
      Resets the image to be empty.
    • getGicon

      public Icon getGicon()
      Gets the `GIcon` being displayed by the `GtkImage`.

      The storage type of the image must be %GTK_IMAGE_EMPTY or
      %GTK_IMAGE_GICON (see [method@Gtk.Image.get_storage_type]).
      The caller of this function does not own a reference to the
      returned `GIcon`.
      Returns:
      a `GIcon`
    • getIconName

      public Str getIconName()
      Gets the icon name and size being displayed by the `GtkImage`.

      The storage type of the image must be %GTK_IMAGE_EMPTY or
      %GTK_IMAGE_ICON_NAME (see [method@Gtk.Image.get_storage_type]).
      The returned string is owned by the `GtkImage` and should not
      be freed.
      Returns:
      the icon name
    • getIconSize

      public int getIconSize()
      Gets the icon size used by the @image when rendering icons.
      Returns:
      the image size used by icons
    • getPaintable

      public Paintable getPaintable()
      Gets the image `GdkPaintable` being displayed by the `GtkImage`.

      The storage type of the image must be %GTK_IMAGE_EMPTY or
      %GTK_IMAGE_PAINTABLE (see [method@Gtk.Image.get_storage_type]).
      The caller of this function does not own a reference to the
      returned paintable.
      Returns:
      the displayed paintable
    • getPixelSize

      public int getPixelSize()
      Gets the pixel size used for named icons.
      Returns:
      the pixel size used for named icons.
    • getStorageType

      public int getStorageType()
      Gets the type of representation being used by the `GtkImage`
      to store image data.

      If the `GtkImage` has no image data, the return value will
      be %GTK_IMAGE_EMPTY.
      Returns:
      image representation being used
    • setFromFile

      public void setFromFile(@Nullable Str filename)
      Sets a `GtkImage` to show a file.

      See [ctor@Gtk.Image.new_from_file] for details.
      Parameters:
      filename - a filename
    • setFromFile

      public void setFromFile(String filename)
      Sets a `GtkImage` to show a file.

      See [ctor@Gtk.Image.new_from_file] for details.
      Parameters:
      filename - a filename
    • setFromGicon

      public void setFromGicon(@Nonnull Icon icon)
      Sets a `GtkImage` to show a `GIcon`.

      See [ctor@Gtk.Image.new_from_gicon] for details.
      Parameters:
      icon - an icon
    • setFromIconName

      public void setFromIconName(@Nullable Str icon_name)
      Sets a `GtkImage` to show a named icon.

      See [ctor@Gtk.Image.new_from_icon_name] for details.
      Parameters:
      icon_name - an icon name
    • setFromIconName

      public void setFromIconName(String icon_name)
      Sets a `GtkImage` to show a named icon.

      See [ctor@Gtk.Image.new_from_icon_name] for details.
      Parameters:
      icon_name - an icon name
    • setFromPaintable

      public void setFromPaintable(@Nullable Paintable paintable)
      Sets a `GtkImage` to show a `GdkPaintable`.

      See [ctor@Gtk.Image.new_from_paintable] for details.
      Parameters:
      paintable - a `GdkPaintable`
    • setFromPixbuf

      public void setFromPixbuf(@Nullable Pixbuf pixbuf)
      Sets a `GtkImage` to show a `GdkPixbuf`.

      See [ctor@Gtk.Image.new_from_pixbuf] for details.

      Note: This is a helper for [method@Gtk.Image.set_from_paintable],
      and you can't get back the exact pixbuf once this is called,
      only a paintable.
      Parameters:
      pixbuf - a `GdkPixbuf` or `NULL`
    • setFromResource

      public void setFromResource(@Nullable Str resource_path)
      Sets a `GtkImage` to show a resource.

      See [ctor@Gtk.Image.new_from_resource] for details.
      Parameters:
      resource_path - a resource path
    • setFromResource

      public void setFromResource(String resource_path)
      Sets a `GtkImage` to show a resource.

      See [ctor@Gtk.Image.new_from_resource] for details.
      Parameters:
      resource_path - a resource path
    • setIconSize

      public void setIconSize(int icon_size)
      Suggests an icon size to the theme for named icons.
      Parameters:
      icon_size - the new icon size
    • setPixelSize

      public void setPixelSize(int pixel_size)
      Sets the pixel size to use for named icons.

      If the pixel size is set to a value != -1, it is used instead
      of the icon size set by [method@Gtk.Image.set_from_icon_name].
      Parameters:
      pixel_size - the new pixel size
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class Widget
      Returns:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class Widget
      Returns:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class Widget
      Returns:
      ConstraintTarget
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()