Image
open class Image : Widget, ImageProtocol
The GtkImage widget displays an image.

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
Imageinstance.Declaration
Swift
@inlinable public init(_ op: UnsafeMutablePointer<GtkImage>)Parameters
oppointer to the underlying object
-
Designated initialiser from a constant pointer to the underlying
Cdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theImageinstance.Declaration
Swift
@inlinable public init(_ op: UnsafePointer<GtkImage>)Parameters
oppointer to the underlying object
-
Optional initialiser from a non-mutating
gpointerto the underlyingCdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theImageinstance.Declaration
Swift
@inlinable override public init!(gpointer op: gpointer?)Parameters
opgpointer to the underlying object
-
Optional initialiser from a non-mutating
gconstpointerto the underlyingCdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theImageinstance.Declaration
Swift
@inlinable override public init!(gconstpointer op: gconstpointer?)Parameters
oppointer to the underlying object
-
Optional initialiser from a constant pointer to the underlying
Cdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theImageinstance.Declaration
Swift
@inlinable public init!(_ op: UnsafePointer<GtkImage>?)Parameters
oppointer to the underlying object
-
Optional initialiser from the underlying
Cdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theImageinstance.Declaration
Swift
@inlinable public init!(_ op: UnsafeMutablePointer<GtkImage>?)Parameters
oppointer to the underlying object
-
Designated initialiser from the underlying
Cdata type. Will retainGtkImage. i.e., ownership is transferred to theImageinstance.Declaration
Swift
@inlinable public init(retaining op: UnsafeMutablePointer<GtkImage>)Parameters
oppointer to the underlying object
-
Reference intialiser for a related type that implements
ImageProtocolWill retainGtkImage.Declaration
Swift
@inlinable public init<T>(image other: T) where T : ImageProtocolParameters
otheran 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
cPointerpointer 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
cPointerpointer 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
praw 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
pmutable 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
rawmutable 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
popaque 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
popaque pointer to the underlying object
-
Creates a new empty
GtkImagewidget.Declaration
Swift
@inlinable public init() -
Creates a new
GtkImagedisplaying the filefilename.If the file isn’t found or can’t be loaded, the resulting
GtkImagewill display a “broken image” icon. This function never returnsnil, it always returns a validGtkImagewidget.If you need to detect failures to load the file, use [ctor
Gdk.Texture.new_from_file] to load the file yourself, then create theGtkImagefrom the texture.The storage type (see [method
Gtk.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
GtkImagedisplaying 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
GtkImagedisplaying 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
GtkImagedisplayingpaintable.The
GtkImagedoes not assume a reference to the paintable; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.The
GtkImagewill track changes to thepaintableand update its size and contents in response to it.Declaration
Swift
@inlinable public init<PaintableT>(paintable: PaintableT?) where PaintableT : PaintableProtocol -
Creates a new
GtkImagedisplayingpixbuf.The
GtkImagedoes not assume a reference to the pixbuf; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.This is a helper for [ctor
Gtk.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
GtkImagefrom the pixbuf. TheGtkImagecreated 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
GtkImagedisplaying the resource fileresource_path.If the file isn’t found or can’t be loaded, the resulting
GtkImagewill display a “broken image” icon. This function never returnsnil, it always returns a validGtkImagewidget.If you need to detect failures to load the file, use [ctor
GdkPixbuf.Pixbuf.new_from_file] to load the file yourself, then create theGtkImagefrom the pixbuf.The storage type (see [method
Gtk.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
GtkImagedisplaying the filefilename.If the file isn’t found or can’t be loaded, the resulting
GtkImagewill display a “broken image” icon. This function never returnsnil, it always returns a validGtkImagewidget.If you need to detect failures to load the file, use [ctor
Gdk.Texture.new_from_file] to load the file yourself, then create theGtkImagefrom the texture.The storage type (see [method
Gtk.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
GtkImagedisplaying 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
GtkImagedisplaying 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
GtkImagedisplayingpaintable.The
GtkImagedoes not assume a reference to the paintable; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.The
GtkImagewill track changes to thepaintableand 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
GtkImagedisplayingpixbuf.The
GtkImagedoes not assume a reference to the pixbuf; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.This is a helper for [ctor
Gtk.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
GtkImagefrom the pixbuf. TheGtkImagecreated 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
GtkImagedisplaying the resource fileresource_path.If the file isn’t found or can’t be loaded, the resulting
GtkImagewill display a “broken image” icon. This function never returnsnil, it always returns a validGtkImagewidget.If you need to detect failures to load the file, use [ctor
GdkPixbuf.Pixbuf.new_from_file] to load the file yourself, then create theGtkImagefrom the pixbuf.The storage type (see [method
Gtk.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!
View on GitHub
Install in Dash
Image Class Reference