Picture

open class Picture : Widget, PictureProtocol

The GtkPicture widget displays a GdkPaintable.

An example GtkPicture

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 [ctorGdk.Texture.new_from_file], then create the GtkPicture with [ctorGtk.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, [ctorGtk.Picture.new_for_resource] and [methodGtk.Picture.set_resource] should be used.

GtkPicture displays an image at its natural size. See [classGtk.Image] 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 turning off [propertyGtk.Picture:keep-aspect-ratio] you can allow the paintable to get stretched. [propertyGtk.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 [propertyGtkWidget:halign] and [propertyGtkWidget: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.

The Picture type acts as a reference-counted owner of an underlying GtkPicture instance. It provides the methods that can operate on this data type through PictureProtocol conformance. Use Picture as a strong reference or owner of a GtkPicture instance.

  • Designated initialiser from the underlying `C` data type.
    

    This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the Picture instance.

    Declaration

    Swift

    @inlinable
    public init(_ op: UnsafeMutablePointer<GtkPicture>)

    Parameters

    op

    pointer to the underlying object

  • Designated initialiser from a constant pointer to the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the Picture instance.

    Declaration

    Swift

    @inlinable
    public init(_ op: UnsafePointer<GtkPicture>)

    Parameters

    op

    pointer to the underlying object

  • Optional initialiser from a non-mutating gpointer to the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the Picture instance.

    Declaration

    Swift

    @inlinable
    override public init!(gpointer op: gpointer?)

    Parameters

    op

    gpointer to the underlying object

  • Optional initialiser from a non-mutating gconstpointer to the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the Picture instance.

    Declaration

    Swift

    @inlinable
    override public init!(gconstpointer op: gconstpointer?)

    Parameters

    op

    pointer to the underlying object

  • Optional initialiser from a constant pointer to the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the Picture instance.

    Declaration

    Swift

    @inlinable
    public init!(_ op: UnsafePointer<GtkPicture>?)

    Parameters

    op

    pointer to the underlying object

  • Optional initialiser from the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the Picture instance.

    Declaration

    Swift

    @inlinable
    public init!(_ op: UnsafeMutablePointer<GtkPicture>?)

    Parameters

    op

    pointer to the underlying object

  • Designated initialiser from the underlying C data type. Will retain GtkPicture. i.e., ownership is transferred to the Picture instance.

    Declaration

    Swift

    @inlinable
    public init(retaining op: UnsafeMutablePointer<GtkPicture>)

    Parameters

    op

    pointer to the underlying object

  • Reference intialiser for a related type that implements PictureProtocol Will retain GtkPicture.

    Declaration

    Swift

    @inlinable
    public init<T>(picture other: T) where T : PictureProtocol

    Parameters

    other

    an instance of a related type that implements PictureProtocol

  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PictureProtocol.

    Declaration

    Swift

    @inlinable
    override public init<T>(cPointer p: UnsafeMutablePointer<T>)

    Parameters

    cPointer

    pointer to the underlying object

  • Unsafe typed, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PictureProtocol.

    Declaration

    Swift

    @inlinable
    override public init<T>(retainingCPointer cPointer: UnsafeMutablePointer<T>)

    Parameters

    cPointer

    pointer to the underlying object

  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PictureProtocol.

    Declaration

    Swift

    @inlinable
    override public init(raw p: UnsafeRawPointer)

    Parameters

    p

    raw pointer to the underlying object

  • Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PictureProtocol.

    Declaration

    Swift

    @inlinable
    override public init(retainingRaw raw: UnsafeRawPointer)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PictureProtocol.

    Declaration

    Swift

    @inlinable
    public required init(raw p: UnsafeMutableRawPointer)

    Parameters

    p

    mutable raw pointer to the underlying object

  • Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PictureProtocol.

    Declaration

    Swift

    @inlinable
    required public init(retainingRaw raw: UnsafeMutableRawPointer)

    Parameters

    raw

    mutable raw pointer to the underlying object

  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PictureProtocol.

    Declaration

    Swift

    @inlinable
    override public init(opaquePointer p: OpaquePointer)

    Parameters

    p

    opaque pointer to the underlying object

  • Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PictureProtocol.

    Declaration

    Swift

    @inlinable
    override public init(retainingOpaquePointer p: OpaquePointer)

    Parameters

    p

    opaque pointer to the underlying object

  • Creates a new empty GtkPicture widget.

    Declaration

    Swift

    @inlinable
    public init()
  • 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 [ctorGdk.Texture.new_from_file] to load the file yourself, then create the GtkPicture from the texture.

    Declaration

    Swift

    @inlinable
    public init<FileT>(file: FileT?) where FileT : FileProtocol
  • Creates a new GtkPicture displaying the file filename.

    This is a utility function that calls [ctorGtk.Picture.new_for_file]. See that function for details.

    Declaration

    Swift

    @inlinable
    public init(filename: UnsafePointer<CChar>? = nil)
  • Creates a new GtkPicture displaying paintable.

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

    Declaration

    Swift

    @inlinable
    public init<PaintableT>(paintable: PaintableT?) where PaintableT : PaintableProtocol
  • Creates a new GtkPicture displaying pixbuf.

    This is a utility function that calls [ctorGtk.Picture.new_for_paintable], See that function for details.

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

    Declaration

    Swift

    @inlinable
    public init<PixbufT>(pixbuf: PixbufT?) where PixbufT : PixbufProtocol
  • Creates a new GtkPicture displaying the resource at resource_path.

    This is a utility function that calls [ctorGtk.Picture.new_for_file]. See that function for details.

    Declaration

    Swift

    @inlinable
    public init(resource resourcePath: UnsafePointer<CChar>? = nil)
  • 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 [ctorGdk.Texture.new_from_file] to load the file yourself, then create the GtkPicture from the texture.

    Declaration

    Swift

    @inlinable
    public static func newFor<FileT>(file: FileT?) -> Widget! where FileT : FileProtocol
  • Creates a new GtkPicture displaying the file filename.

    This is a utility function that calls [ctorGtk.Picture.new_for_file]. See that function for details.

    Declaration

    Swift

    @inlinable
    public static func newFor(filename: UnsafePointer<CChar>? = nil) -> Widget!
  • Creates a new GtkPicture displaying paintable.

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

    Declaration

    Swift

    @inlinable
    public static func newFor<PaintableT>(paintable: PaintableT?) -> Widget! where PaintableT : PaintableProtocol
  • Creates a new GtkPicture displaying pixbuf.

    This is a utility function that calls [ctorGtk.Picture.new_for_paintable], See that function for details.

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

    Declaration

    Swift

    @inlinable
    public static func newFor<PixbufT>(pixbuf: PixbufT?) -> Widget! where PixbufT : PixbufProtocol
  • Creates a new GtkPicture displaying the resource at resource_path.

    This is a utility function that calls [ctorGtk.Picture.new_for_file]. See that function for details.

    Declaration

    Swift

    @inlinable
    public static func newFor(resource resourcePath: UnsafePointer<CChar>? = nil) -> Widget!