1.147 <GtkPicture>

Class: <GtkPicture>

It derives from <GtkWidget>.

Displays a <GdkPaintable>.

Many convenience functions are provided to make pictures simple to use. For example, if you want to load an image from a file, and then display it, there’s a convenience function to do this:

GtkWidget *widget = gtk_picture_new_for_filename ("myfile.png");

If the file isn’t loaded successfully, the picture 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 and image loading framework such as libglycin, then create the <GtkPicture> with picture:new-for-paintable.

Sometimes an application will want to avoid depending on external data files, such as image files. See the documentation of <GResource> for details. In this case, picture:new-for-resource and picture:set-resource should be used.

<GtkPicture> displays an image at its natural size. See <GtkImage> if you want to display a fixed-size image, such as an icon.

Sizing the paintable

You can influence how the paintable is displayed inside the <GtkPicture> by changing picture:content-fit. See <GtkContentFit> for details. picture:can-shrink can be unset to make sure that paintables are never made smaller than their ideal size - but be careful if you do not know the size of the paintable in use (like when displaying user-loaded images). This can easily cause the picture to grow larger than the screen. And widget:halign and widget:valign can be used to make sure the paintable doesn’t fill all available space but is instead displayed at its original size.

CSS nodes

<GtkPicture> has a single CSS node with the name picture.

Accessibility

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

Properties

Property: picture:alternative-text self

The alternative textual description for the picture.

Its value is a string, or #f.

Set it with (set! (picture:alternative-text self) value).

Property: picture:can-shrink self

If the <GtkPicture> can be made smaller than the natural size of its contents.

Its value is a boolean.

Set it with (set! (picture:can-shrink self) value).

Property: picture:content-fit self

How the content should be resized to fit inside the <GtkPicture>.

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

Set it with (set! (picture:content-fit self) value).

Property: picture:file self

The <GFile> that is displayed or #f if none.

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

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

Property: picture:isolate-contents self

If the rendering of the contents is isolated from the rest of the widget tree.

Its value is a boolean.

Set it with (set! (picture:isolate-contents self) value).

Property: picture:keep-aspect-ratio self

Whether the GtkPicture will render its contents trying to preserve the aspect ratio.

Its value is a boolean.

Set it with (set! (picture:keep-aspect-ratio self) value).

Property: picture:paintable self

The <GdkPaintable> to be displayed by this <GtkPicture>.

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

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

Procedures

Method: picture:get-alternative-text self ⇒ %return
Method: get-alternative-text self ⇒ %return

Gets the alternative textual description of the picture.

The returned string will be #f if the picture cannot be described textually.

self

Passed: a <GtkPicture>.

a <GtkPicture>

%return

Returned: a string, or #f.

the alternative textual description of self.

Method: picture:get-can-shrink? self ⇒ %return
Method: get-can-shrink? self ⇒ %return

Returns whether the <GtkPicture> respects its contents size.

self

Passed: a <GtkPicture>.

a <GtkPicture>

%return

Returned: a boolean.

#t if the picture can be made smaller than its contents

Method: picture:get-content-fit self ⇒ %return
Method: get-content-fit self ⇒ %return

Returns the fit mode for the content of the <GtkPicture>.

See <GtkContentFit> for details.

self

Passed: a <GtkPicture>.

a <GtkPicture>

%return

Returned: a <GtkContentFit>.

the content fit mode

Method: picture:get-file self ⇒ %return
Method: get-file self ⇒ %return

Gets the <GFile> currently displayed if self is displaying a file.

If self is not displaying a file, for example when picture:set-paintable was used, then #f is returned.

self

Passed: a <GtkPicture>.

a <GtkPicture>

%return

Returned: a <GFile>, or #f.

The <GFile> displayed by self.

Method: picture:get-isolate-contents? self ⇒ %return
Method: get-isolate-contents? self ⇒ %return

Returns whether the contents are isolated.

self

Passed: a <GtkPicture>.

a <GtkPicture>

%return

Returned: a boolean.

True if contents are isolated

Method: picture:get-keep-aspect-ratio? self ⇒ %return
Method: get-keep-aspect-ratio? self ⇒ %return

Returns whether the <GtkPicture> preserves its contents aspect ratio.

self

Passed: a <GtkPicture>.

a <GtkPicture>

%return

Returned: a boolean.

#t if the self tries to keep the contents’ aspect ratio

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

Gets the <GdkPaintable> being displayed by the <GtkPicture>.

self

Passed: a <GtkPicture>.

a <GtkPicture>

%return

Returned: a <GdkPaintable>, or #f.

the displayed paintable

Procedure: picture:new ⇒ %return

Creates a new empty <GtkPicture> widget.

%return

Returned: a <GtkWidget>.

a newly created <GtkPicture> widget.

Procedure: picture:new-for-file [file] ⇒ %return

Creates a new <GtkPicture> displaying the given file.

If the file isn’t found or can’t be loaded, the resulting <GtkPicture> is empty.

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 <GtkPicture> from the texture.

file

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

a <GFile>

%return

Returned: a <GtkWidget>.

a new <GtkPicture>

Procedure: picture:new-for-filename [filename] ⇒ %return

Creates a new <GtkPicture> displaying the file filename.

This is a utility function that calls picture:new-for-file. See that function for details.

filename

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

a filename

%return

Returned: a <GtkWidget>.

a new <GtkPicture>

Procedure: picture:new-for-paintable [paintable] ⇒ %return

Creates a new <GtkPicture> displaying paintable.

The <GtkPicture> will track changes to the paintable and update its size and contents in response to it.

paintable

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

a <GdkPaintable>

%return

Returned: a <GtkWidget>.

a new <GtkPicture>

Procedure: picture:new-for-pixbuf [pixbuf] ⇒ %return

Creates a new <GtkPicture> displaying pixbuf.

This is a utility function that calls picture:new-for-paintable, See that function for details.

The pixbuf must not be modified after passing it to this function.

pixbuf

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

a <GdkPixbuf>

%return

Returned: a <GtkWidget>.

a new <GtkPicture>

Procedure: picture:new-for-resource [resource-path] ⇒ %return

Creates a new <GtkPicture> displaying the resource at resource-path.

This is a utility function that calls picture:new-for-file. See that function for details.

resource-path

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

resource path to play back

%return

Returned: a <GtkWidget>.

a new <GtkPicture>

Method: picture:set-alternative-text self [alternative-text]
Method: set-alternative-text self [alternative-text]

Sets an alternative textual description for the picture contents.

It is equivalent to the "alt" attribute for images on websites.

This text will be made available to accessibility tools.

If the picture cannot be described textually, set this property to #f.

self

Passed: a <GtkPicture>.

a <GtkPicture>

alternative-text

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

a textual description of the contents

Method: picture:set-can-shrink self can-shrink
Method: set-can-shrink self can-shrink

If set to #t, then self can be made smaller than its contents.

The contents will then be scaled down when rendering.

If you want to still force a minimum size manually, consider using widget:set-size-request.

Also of note is that a similar function for growing does not exist because the grow behavior can be controlled via widget:set-halign and widget:set-valign.

self

Passed: a <GtkPicture>.

a <GtkPicture>

can-shrink

Passed: a boolean.

if self can be made smaller than its contents

Method: picture:set-content-fit self content-fit
Method: set-content-fit self content-fit

Sets how the content should be resized to fit the <GtkPicture>.

See <GtkContentFit> for details.

self

Passed: a <GtkPicture>.

a <GtkPicture>

content-fit

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

the content fit mode

Method: picture:set-file self [file]
Method: set-file self [file]

Makes self load and display file.

See picture:new-for-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 <GtkPicture>.

a <GtkPicture>

file

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

a <GFile>

Method: picture:set-filename self [filename]
Method: set-filename self [filename]

Makes self load and display the given filename.

This is a utility function that calls picture:set-file.

::: 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 <GtkPicture>.

a <GtkPicture>

filename

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

the filename to play

Method: picture:set-isolate-contents self isolate-contents
Method: set-isolate-contents self isolate-contents

If set to true, then the contents will be rendered individually.

If set to false they will be able to erase or otherwise mix with the background.

GTK supports finer grained isolation, in rare cases where you need this, you can use snapshot:push-isolation yourself to achieve this.

By default contents are isolated.

self

Passed: a <GtkPicture>.

a <GtkPicture>

isolate-contents

Passed: a boolean.

if contents are rendered separately

Method: picture:set-keep-aspect-ratio self keep-aspect-ratio
Method: set-keep-aspect-ratio self keep-aspect-ratio

If set to #t, the self will render its contents according to their aspect ratio.

That means that empty space may show up at the top/bottom or left/right of self.

If set to #f or if the contents provide no aspect ratio, the contents will be stretched over the picture’s whole area.

self

Passed: a <GtkPicture>.

a <GtkPicture>

keep-aspect-ratio

Passed: a boolean.

whether to keep aspect ratio

Method: picture:set-paintable self [paintable]
Method: set-paintable self [paintable]

Makes self display the given paintable.

If paintable is NULL, nothing will be displayed.

See picture:new-for-paintable for details.

self

Passed: a <GtkPicture>.

a <GtkPicture>

paintable

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

a <GdkPaintable>

Method: picture:set-pixbuf self [pixbuf]
Method: set-pixbuf self [pixbuf]

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

See picture:new-for-pixbuf for details.

This is a utility function that calls picture:set-paintable.

self

Passed: a <GtkPicture>.

a <GtkPicture>

pixbuf

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

a <GdkPixbuf>

Method: picture:set-resource self [resource-path]
Method: set-resource self [resource-path]

Makes self load and display the resource at the given resource-path.

This is a utility function that calls picture:set-file.

self

Passed: a <GtkPicture>.

a <GtkPicture>

resource-path

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

the resource to set