The `GtkPicture` widget displays a `GdkPaintable`.
![An example GtkPicture](picture.png)
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:
```c 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 [
[email protected]_from_file], then create the `GtkPicture` with [[email protected]_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, [[email protected]_for_resource] and [[email protected]_resource] should be used.
`GtkPicture` displays an image at its natural size. See [[email protected]] 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 [[email protected]:content-fit]. See [
[email protected]] for details. [[email protected]: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 [property@GtkWidget:halign] and [property@GtkWidget: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_ACCESSIBLE_ROLE_IMG` role.
- public unowned string? get_alternative_text ()
Gets the alternative textual description of the picture.
- public bool get_can_shrink ()
Returns whether the `GtkPicture` respects its contents size.
- public ContentFit get_content_fit ()
Returns the fit mode for the content of the `GtkPicture`.
- public unowned File? get_file ()
Gets the `GFile` currently displayed if
this is displaying a file.
- public bool get_keep_aspect_ratio ()
Returns whether the `GtkPicture` preserves its contents aspect ratio.
- public unowned Paintable? get_paintable ()
Gets the `GdkPaintable` being displayed by the `GtkPicture`.
- public void set_alternative_text (string? alternative_text)
Sets an alternative textual description for the picture contents.
- public void set_can_shrink (bool can_shrink)
If set to true, the
this can be made smaller than its contents.
- public void set_content_fit (ContentFit content_fit)
Sets how the content should be resized to fit the `GtkPicture`.
- public void set_file (File? file)
Makes this load and display
file
.
- public void set_filename (string? filename)
Makes this load and display the
given filename
.
- public void set_keep_aspect_ratio (bool keep_aspect_ratio)
If set to true, the
this will render its contents according to their aspect ratio.
- public void set_paintable (Paintable? paintable)
Makes this display the given
paintable
.
- public void set_pixbuf (Pixbuf? pixbuf)
Sets a `GtkPicture` to show a `GdkPixbuf`.
- public void set_resource (string? resource_path)
Makes this load and display the
resource at the given resource_path
.