1.102 <GtkImage>

Class: <GtkImage>

It derives from <GtkWidget>.

Displays an image.

Various kinds of object can be displayed as an image; most typically, you would load a <GdkTexture> from a file, using the convenience function image:new-from-file, for instance:

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 an image loading framework such as libglycin, then create the <GtkImage> with 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, image:resource, image:new-from-resource, and image:set-from-resource should be used.

<GtkImage> displays its image as an icon, with a size that is determined by the application. See <GtkPicture> 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 image:icon-size property.

Accessibility

<GtkImage> uses the Gtk.AccessibleRole.img role.

Properties

Property: image:file self

A path to the file to display.

Its value is a string, or #f.

Set it with (set! (image:file self) value).

Property: image:gicon self

The <GIcon> displayed in the GtkImage.

For themed icons, If the icon theme is changed, the image will be updated automatically.

Its value is a <GIcon>, or #f.

Set it with (set! (image:gicon self) value).

Property: image:icon-name self

The name of the icon in the icon theme.

If the icon theme is changed, the image will be updated automatically.

Its value is a string, or #f.

Set it with (set! (image:icon-name self) value).

Property: image:icon-size self

The symbolic size to display icons at.

Its value is a <GtkIconSize> (or, to set it, one of its symbols).

Set it with (set! (image:icon-size self) value).

Property: image:paintable self

The <GdkPaintable> to display.

Its value is a <GdkPaintable>, or #f.

Set it with (set! (image:paintable self) value).

Property: image:pixel-size self

The size in pixels to display icons at.

If set to a value != -1, this property overrides the image:icon-size property for images of type icon-name.

Its value is a 32-bit integer.

Set it with (set! (image:pixel-size self) value).

Property: image:resource self

A path to a resource file to display.

Its value is a string, or #f.

Set it with (set! (image:resource self) value).

Property: image:storage-type self

The representation being used for image data.

Its value is a <GtkImageType>.

It is read only.

Property: image:use-fallback self

Whether the icon displayed in the <GtkImage> will use standard icon names fallback.

The value of this property is only relevant for images of type icon-name and gicon.

Its value is a boolean.

Set it with (set! (image:use-fallback self) value).

Procedures

Method: image:clear self
Method: clear self

Resets the image to be empty.

self

Passed: a <GtkImage>.

a <GtkImage>

Method: image:get-gicon self ⇒ %return
Method: get-gicon self ⇒ %return

Gets the <GIcon> being displayed by the <GtkImage>.

The storage type of the image must be empty or gicon (see image:get-storage-type). The caller of this function does not own a reference to the returned <GIcon>.

self

Passed: a <GtkImage>.

a <GtkImage>

%return

Returned: a <GIcon>, or #f.

a <GIcon>

Method: image:get-icon-name self ⇒ %return
Method: get-icon-name self ⇒ %return

Gets the icon name and size being displayed by the <GtkImage>.

The storage type of the image must be empty or icon-name (see image:get-storage-type). The returned string is owned by the <GtkImage> and should not be freed.

self

Passed: a <GtkImage>.

a <GtkImage>

%return

Returned: a string, or #f.

the icon name

Method: image:get-icon-size self ⇒ %return
Method: get-icon-size self ⇒ %return

Gets the icon size used by the self when rendering icons.

self

Passed: a <GtkImage>.

a <GtkImage>

%return

Returned: a <GtkIconSize>.

the image size used by icons

Method: image:get-paintable self ⇒ %return
Method: get-paintable self ⇒ %return

Gets the image <GdkPaintable> being displayed by the <GtkImage>.

The storage type of the image must be empty or paintable (see image:get-storage-type). The caller of this function does not own a reference to the returned paintable.

self

Passed: a <GtkImage>.

a <GtkImage>

%return

Returned: a <GdkPaintable>, or #f.

the displayed paintable

Method: image:get-pixel-size self ⇒ %return
Method: get-pixel-size self ⇒ %return

Gets the pixel size used for named icons.

self

Passed: a <GtkImage>.

a <GtkImage>

%return

Returned: a 32-bit integer.

the pixel size used for named icons.

Method: image:get-storage-type self ⇒ %return
Method: get-storage-type self ⇒ %return

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 empty.

self

Passed: a <GtkImage>.

a <GtkImage>

%return

Returned: a <GtkImageType>.

image representation being used

Procedure: image:new ⇒ %return

Creates a new empty <GtkImage> widget.

%return

Returned: a <GtkWidget>.

a newly created <GtkImage> widget.

Procedure: image:new-from-file filename ⇒ %return

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 #f, it always returns a valid <GtkImage> widget.

If you need to detect failures to load the file, use an image loading framework such as libglycin to load the file yourself, then create the <GtkImage> from the texture.

The storage type (see image:get-storage-type) of the returned image is not defined, it will be whatever is appropriate for displaying the file.

filename

Passed: a file name, as a string.

a filename

%return

Returned: a <GtkWidget>.

a new <GtkImage>

Procedure: image:new-from-gicon icon ⇒ %return

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.

icon

Passed: a <GIcon>.

an icon

%return

Returned: a <GtkWidget>.

a new <GtkImage> displaying the themed icon

Procedure: image:new-from-icon-name [icon-name] ⇒ %return

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.

icon-name

Passed, or left out: a string, or #f.

an icon name

%return

Returned: a <GtkWidget>.

a new <GtkImage> displaying the themed icon

Procedure: image:new-from-paintable [paintable] ⇒ %return

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.

Note that paintables are still subject to the icon size that is set on the image. If you want to display a paintable at its intrinsic size, use <GtkPicture> instead.

If paintable is a <GtkSymbolicPaintable>, then it will be recolored with the symbolic palette from the theme.

paintable

Passed, or left out: a <GdkPaintable>, or #f.

a <GdkPaintable>

%return

Returned: a <GtkWidget>.

a new <GtkImage>

Procedure: image:new-from-pixbuf [pixbuf] ⇒ %return

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 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 image:new-from-icon-name.

pixbuf

Passed, or left out: a <GdkPixbuf>, or #f.

a <GdkPixbuf>

%return

Returned: a <GtkWidget>.

a new <GtkImage>

Procedure: image:new-from-resource resource-path ⇒ %return

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 #f, it always returns a valid <GtkImage> widget.

If you need to detect failures to load the file, use an image loading framework such as libglycin to load the file yourself, then create the <GtkImage> from the texture.

The storage type (see image:get-storage-type) of the returned image is not defined, it will be whatever is appropriate for displaying the file.

resource-path

Passed: a string.

a resource path

%return

Returned: a <GtkWidget>.

a new <GtkImage>

Method: image:set-from-file self [filename]
Method: set-from-file self [filename]

Sets a <GtkImage> to show a file.

See image:new-from-file for details.

::: warning Note that this function should not be used with untrusted data. Use a proper image loading framework such as libglycin, which can load many image formats into a <GdkTexture>, and then use image:set-from-paintable.

self

Passed: a <GtkImage>.

a <GtkImage>

filename

Passed, or left out: a file name, as a string, or #f.

a filename

Method: image:set-from-gicon self icon
Method: set-from-gicon self icon

Sets a <GtkImage> to show a <GIcon>.

See image:new-from-gicon for details.

self

Passed: a <GtkImage>.

a <GtkImage>

icon

Passed: a <GIcon>.

an icon

Method: image:set-from-icon-name self [icon-name]
Method: set-from-icon-name self [icon-name]

Sets a <GtkImage> to show a named icon.

See image:new-from-icon-name for details.

self

Passed: a <GtkImage>.

a <GtkImage>

icon-name

Passed, or left out: a string, or #f.

an icon name

Method: image:set-from-paintable self [paintable]
Method: set-from-paintable self [paintable]

Sets a <GtkImage> to show a <GdkPaintable>.

See image:new-from-paintable for details.

self

Passed: a <GtkImage>.

a <GtkImage>

paintable

Passed, or left out: a <GdkPaintable>, or #f.

a <GdkPaintable>

Method: image:set-from-pixbuf self [pixbuf]
Method: set-from-pixbuf self [pixbuf]

Sets a <GtkImage> to show a <GdkPixbuf>.

See image:new-from-pixbuf for details.

Note: This is a helper for image:set-from-paintable, and you can’t get back the exact pixbuf once this is called, only a paintable.

self

Passed: a <GtkImage>.

a <GtkImage>

pixbuf

Passed, or left out: a <GdkPixbuf>, or #f.

a <GdkPixbuf> or NULL

Method: image:set-from-resource self [resource-path]
Method: set-from-resource self [resource-path]

Sets a <GtkImage> to show a resource.

See image:new-from-resource for details.

self

Passed: a <GtkImage>.

a <GtkImage>

resource-path

Passed, or left out: a string, or #f.

a resource path

Method: image:set-icon-size self icon-size
Method: set-icon-size self icon-size

Suggests an icon size to the theme for named icons.

self

Passed: a <GtkImage>.

a <GtkImage>

icon-size

Passed: a <GtkIconSize>, or one of its symbols.

the new icon size

Method: image:set-pixel-size self pixel-size
Method: set-pixel-size self 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 image:set-icon-size.

self

Passed: a <GtkImage>.

a <GtkImage>

pixel-size

Passed: a 32-bit integer.

the new pixel size