Image

open class Image : Widget, ImageProtocol

The GtkImage widget displays an image.

An example GtkImage

Various kinds of object can be displayed as an image; most typically, you would load a GdkTexture from a file, using the convenience function [ctorGtk.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 [ctorGdk.Texture.new_from_file], then create the GtkImage with [ctorGtk.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, [propertyGtk.Image:resource], [ctorGtk.Image.new_from_resource], and [methodGtk.Image.set_from_resource] should be used.

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

Accessibility

GtkImage uses the GTK_ACCESSIBLE_ROLE_IMG role.

The Image type acts as a reference-counted owner of an underlying GtkImage instance. It provides the methods that can operate on this data type through ImageProtocol conformance. Use Image as a strong reference or owner of a GtkImage 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 Image instance.

    Declaration

    Swift

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

    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 Image instance.

    Declaration

    Swift

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

    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 Image 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 Image 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 Image instance.

    Declaration

    Swift

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

    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 Image instance.

    Declaration

    Swift

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

    Parameters

    op

    pointer to the underlying object

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

    Declaration

    Swift

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

    Parameters

    op

    pointer to the underlying object

  • Reference intialiser for a related type that implements ImageProtocol Will retain GtkImage.

    Declaration

    Swift

    @inlinable
    public init<T>(image other: T) where T : ImageProtocol

    Parameters

    other

    an instance of a related type that implements ImageProtocol

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

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

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

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

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

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

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

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

    Declaration

    Swift

    @inlinable
    override public init(retainingOpaquePointer p: OpaquePointer)

    Parameters

    p

    opaque pointer to the underlying object

  • Creates a new empty GtkImage widget.

    Declaration

    Swift

    @inlinable
    public init()
  • 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 nil, it always returns a valid GtkImage widget.

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

    The storage type (see [methodGtk.Image.get_storage_type]) of the returned image is not defined, it will be whatever is appropriate for displaying the file.

    Declaration

    Swift

    @inlinable
    public init(file filename: UnsafePointer<CChar>!)
  • 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.

    Declaration

    Swift

    @inlinable
    public init<IconT>(gicon icon: IconT) where IconT : IconProtocol
  • 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.

    Declaration

    Swift

    @inlinable
    public init(iconName: UnsafePointer<CChar>? = nil)
  • 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.

    Declaration

    Swift

    @inlinable
    public init<PaintableT>(paintable: PaintableT?) where PaintableT : PaintableProtocol
  • 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 [ctorGtk.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 [ctorGtk.Image.new_from_icon_name].

    Declaration

    Swift

    @inlinable
    public init<PixbufT>(pixbuf: PixbufT?) where PixbufT : PixbufProtocol
  • 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 nil, it always returns a valid GtkImage widget.

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

    The storage type (see [methodGtk.Image.get_storage_type]) of the returned image is not defined, it will be whatever is appropriate for displaying the file.

    Declaration

    Swift

    @inlinable
    public init(resource resourcePath: UnsafePointer<CChar>!)
  • 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 nil, it always returns a valid GtkImage widget.

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

    The storage type (see [methodGtk.Image.get_storage_type]) of the returned image is not defined, it will be whatever is appropriate for displaying the file.

    Declaration

    Swift

    @inlinable
    public static func newFrom(file filename: UnsafePointer<CChar>!) -> Widget!
  • 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.

    Declaration

    Swift

    @inlinable
    public static func newFromG<IconT>(gicon icon: IconT) -> Widget! where IconT : IconProtocol
  • 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.

    Declaration

    Swift

    @inlinable
    public static func newFrom(iconName: UnsafePointer<CChar>? = nil) -> Widget!
  • 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.

    Declaration

    Swift

    @inlinable
    public static func newFrom<PaintableT>(paintable: PaintableT?) -> Widget! where PaintableT : PaintableProtocol
  • 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 [ctorGtk.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 [ctorGtk.Image.new_from_icon_name].

    Declaration

    Swift

    @inlinable
    public static func newFrom<PixbufT>(pixbuf: PixbufT?) -> Widget! where PixbufT : PixbufProtocol
  • 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 nil, it always returns a valid GtkImage widget.

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

    The storage type (see [methodGtk.Image.get_storage_type]) of the returned image is not defined, it will be whatever is appropriate for displaying the file.

    Declaration

    Swift

    @inlinable
    public static func newFrom(resource resourcePath: UnsafePointer<CChar>!) -> Widget!