ImageRef

public struct ImageRef : ImageProtocol, GWeakCapturing

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 ImageRef type acts as a lightweight Swift reference to an underlying GtkImage instance. It exposes methods that can operate on this data type through ImageProtocol conformance. Use ImageRef only as an unowned reference to an existing GtkImage instance.

  • ptr
    Untyped pointer to the underlying `GtkImage` instance.
    

    For type-safe access, use the generated, typed pointer image_ptr property instead.

    Declaration

    Swift

    public let ptr: UnsafeMutableRawPointer!

Image Class

  • Designated initialiser from the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafeMutablePointer<GtkImage>)
  • Designated initialiser from a constant pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafePointer<GtkImage>)
  • Conditional initialiser from an optional pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafeMutablePointer<GtkImage>?)
  • Conditional initialiser from an optional, non-mutable pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafePointer<GtkImage>?)
  • Conditional initialiser from an optional gpointer

    Declaration

    Swift

    @inlinable
    init!(gpointer g: gpointer?)
  • Conditional initialiser from an optional, non-mutable gconstpointer

    Declaration

    Swift

    @inlinable
    init!(gconstpointer g: gconstpointer?)
  • Reference intialiser for a related type that implements ImageProtocol

    Declaration

    Swift

    @inlinable
    init<T>(_ other: T) where T : ImageProtocol
  • This factory is syntactic sugar for setting weak pointers wrapped in GWeak<T>

    Declaration

    Swift

    @inlinable
    static func unowned<T>(_ other: T) -> ImageRef where T : ImageProtocol
  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ImageProtocol.

    Declaration

    Swift

    @inlinable
    init<T>(cPointer: UnsafeMutablePointer<T>)
  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ImageProtocol.

    Declaration

    Swift

    @inlinable
    init<T>(constPointer: UnsafePointer<T>)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ImageProtocol.

    Declaration

    Swift

    @inlinable
    init(mutating 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
    init(raw: UnsafeMutableRawPointer)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ImageProtocol.

    Declaration

    Swift

    @inlinable
    init(opaquePointer: OpaquePointer)
  • Creates a new empty GtkImage widget.

    Declaration

    Swift

    @inlinable
    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
    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
    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
    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
    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
    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
    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
    static func newFrom(file filename: UnsafePointer<CChar>!) -> WidgetRef!
  • 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
    static func newFromG<IconT>(gicon icon: IconT) -> WidgetRef! 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
    static func newFrom(iconName: UnsafePointer<CChar>? = nil) -> WidgetRef!
  • 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
    static func newFrom<PaintableT>(paintable: PaintableT?) -> WidgetRef! 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
    static func newFrom<PixbufT>(pixbuf: PixbufT?) -> WidgetRef! 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
    static func newFrom(resource resourcePath: UnsafePointer<CChar>!) -> WidgetRef!