Class Image
- All Implemented Interfaces:
Accessible,Buildable,ConstraintTarget,Proxy
Various kinds of object can be displayed as an image; most typically,
you would load a GdkTexture from a file, using the convenience function
fromFile(java.lang.String), 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 an image
loading framework such as libglycin, then create the GtkImage with
fromPaintable(org.gnome.gdk.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, Gtk.Image:resource,
fromResource(java.lang.String), and setFromResource(java.lang.String)
should be used.
GtkImage displays its image as an icon, with a size that is determined
by the application. See 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
Gtk.Image:icon-size property.
Accessibility
GtkImage uses the Gtk.AccessibleRole.img role.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classImage.Builder<B extends Image.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class org.gnome.gtk.Widget
Widget.DestroyCallback, Widget.DirectionChangedCallback, Widget.HideCallback, Widget.KeynavFailedCallback, Widget.MapCallback, Widget.MnemonicActivateCallback, Widget.MoveFocusCallback, Widget.QueryTooltipCallback, Widget.RealizeCallback, Widget.ShowCallback, Widget.StateFlagsChangedCallback, Widget.UnmapCallback, Widget.UnrealizeCallback, Widget.Widget$Impl, Widget.WidgetClassNested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface org.gnome.gtk.Accessible
Accessible.Accessible$Impl, Accessible.AccessibleInterfaceNested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.Buildable$Impl, Buildable.BuildableIfaceNested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTarget$Impl, ConstraintTarget.ConstraintTargetInterface -
Constructor Summary
ConstructorsConstructorDescriptionImage()Creates a new Image.Image(MemorySegment address) Create a Image proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected ImageasParent()Returns this instance as if it were its parent type.static Image.Builder<? extends Image.Builder> builder()AImage.Builderobject constructs aImagewith the specified properties.voidclear()Resets the image to be empty.static ImageCreates a newGtkImagedisplaying the filefilename.static ImageCreates aGtkImagedisplaying an icon from the current icon theme.static ImagefromIconName(@Nullable String iconName) Creates aGtkImagedisplaying an icon from the current icon theme.static ImagefromPaintable(@Nullable Paintable paintable) Creates a newGtkImagedisplayingpaintable.static ImagefromPixbuf(@Nullable Pixbuf pixbuf) Deprecated.static ImagefromResource(String resourcePath) Creates a newGtkImagedisplaying the resource fileresourcePath.@Nullable IcongetGicon()Gets theGIconbeing displayed by theGtkImage.@Nullable StringGets the icon name and size being displayed by theGtkImage.Gets the icon size used by the this Image when rendering icons.@Nullable PaintableGets the imageGdkPaintablebeing displayed by theGtkImage.intGets the pixel size used for named icons.Gets the type of representation being used by theGtkImageto store image data.static @Nullable TypegetType()Get the GType of the Image classvoidsetFromFile(@Nullable String filename) Sets aGtkImageto show a file.voidsetFromGicon(Icon icon) Sets aGtkImageto show aGIcon.voidsetFromIconName(@Nullable String iconName) Sets aGtkImageto show a named icon.voidsetFromPaintable(@Nullable Paintable paintable) Sets aGtkImageto show aGdkPaintable.voidsetFromPixbuf(@Nullable Pixbuf pixbuf) Deprecated.UsesetFromPaintable(org.gnome.gdk.Paintable)insteadvoidsetFromResource(@Nullable String resourcePath) Sets aGtkImageto show a resource.voidsetIconSize(IconSize iconSize) Suggests an icon size to the theme for named icons.voidsetPixelSize(int pixelSize) Sets the pixel size to use for named icons.Methods inherited from class org.gnome.gtk.Widget
actionSetEnabled, activateActionIfExists, activateDefault, activateWidget, addController, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, cssChanged, directionChanged, disposeTemplate, dragCheckThreshold, emitDestroy, emitDirectionChanged, emitHide, emitKeynavFailed, emitMap, emitMnemonicActivate, emitMoveFocus, emitQueryTooltip, emitRealize, emitShow, emitStateFlagsChanged, emitUnmap, emitUnrealize, errorBell, focus, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getBaseline, getCanFocus, getCanTarget, getChildVisible, getClipboard, getColor, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getLimitEvents, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getMemoryLayout, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, moveFocus, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, pick, queryTooltip, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeMnemonicLabel, removeTickCallback, root, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setLimitEvents, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setStateFlags, setTooltipMarkup, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, sizeAllocate, snapshot, snapshotChild, stateFlagsChanged, systemSettingChanged, translateCoordinates, triggerTooltipQuery, unmap, unparent, unrealize, unroot, unsetStateFlags, unsetStateFlagsMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gnome.gtk.Accessible
announce, getAccessibleParent, getAccessibleRole, getAtContext, getBounds, getFirstAccessibleChild, getNextAccessibleSibling, getPlatformState, resetProperty, resetRelation, resetState, setAccessibleParent, updateNextAccessibleSibling, updatePlatformState, updateProperty, updateRelation, updateStateMethods inherited from interface org.gnome.gtk.Buildable
getBuildableId
-
Constructor Details
-
Image
Create a Image proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Image
public Image()Creates a new Image.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
fromFile
Creates a newGtkImagedisplaying the filefilename.If the file isn’t found or can’t be loaded, the resulting
GtkImagewill display a “broken image” icon. This function never returnsnull, it always returns a validGtkImagewidget.If you need to detect failures to load the file, use an image loading framework such as libglycin to load the file yourself, then create the
GtkImagefrom the texture.The storage type (see
getStorageType()) of the returned image is not defined, it will be whatever is appropriate for displaying the file.- Parameters:
filename- a filename- Returns:
- a new
GtkImage
-
fromGicon
Creates aGtkImagedisplaying 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.
- Parameters:
icon- an icon- Returns:
- a new
GtkImagedisplaying the themed icon
-
fromIconName
Creates aGtkImagedisplaying 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.
- Parameters:
iconName- an icon name- Returns:
- a new
GtkImagedisplaying the themed icon
-
fromPaintable
Creates a newGtkImagedisplayingpaintable.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.Note that paintables are still subject to the icon size that is set on the image. If you want to display a paintable at its intrinsic size, use
Pictureinstead.If
paintableis aSymbolicPaintable, then it will be recolored with the symbolic palette from the theme.- Parameters:
paintable- aGdkPaintable- Returns:
- a new
GtkImage
-
fromPixbuf
Deprecated.Creates a newGtkImagedisplayingpixbuf.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
fromPaintable(org.gnome.gdk.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 usefromIconName(java.lang.String).- Parameters:
pixbuf- aGdkPixbuf- Returns:
- a new
GtkImage
-
fromResource
Creates a newGtkImagedisplaying the resource fileresourcePath.If the file isn’t found or can’t be loaded, the resulting
GtkImagewill display a “broken image” icon. This function never returnsnull, it always returns a validGtkImagewidget.If you need to detect failures to load the file, use an image loading framework such as libglycin to load the file yourself, then create the
GtkImagefrom the texture.The storage type (see
getStorageType()) of the returned image is not defined, it will be whatever is appropriate for displaying the file.- Parameters:
resourcePath- a resource path- Returns:
- a new
GtkImage
-
clear
public void clear()Resets the image to be empty. -
getGicon
Gets theGIconbeing displayed by theGtkImage.The storage type of the image must be
ImageType.EMPTYorImageType.GICON(seegetStorageType()). The caller of this function does not own a reference to the returnedGIcon.- Returns:
- a
GIcon
-
getIconName
Gets the icon name and size being displayed by theGtkImage.The storage type of the image must be
ImageType.EMPTYorImageType.ICON_NAME(seegetStorageType()). The returned string is owned by theGtkImageand should not be freed.- Returns:
- the icon name
-
getIconSize
Gets the icon size used by the this Image when rendering icons.- Returns:
- the image size used by icons
-
getPaintable
Gets the imageGdkPaintablebeing displayed by theGtkImage.The storage type of the image must be
ImageType.EMPTYorImageType.PAINTABLE(seegetStorageType()). The caller of this function does not own a reference to the returned paintable.- Returns:
- the displayed paintable
-
getPixelSize
public int getPixelSize()Gets the pixel size used for named icons.- Returns:
- the pixel size used for named icons.
-
getStorageType
Gets the type of representation being used by theGtkImageto store image data.If the
GtkImagehas no image data, the return value will beImageType.EMPTY.- Returns:
- image representation being used
-
setFromFile
Sets aGtkImageto show a file.See
fromFile(java.lang.String)for details.Warning Note that this function should not be used with untrusted data. Use a proper image loading framework such as libglycin, which can load many image formats into a
GdkTexture, and then use [method@Gtk.Image.set_from_paintable].- Parameters:
filename- a filename
-
setFromGicon
- Parameters:
icon- an icon
-
setFromIconName
Sets aGtkImageto show a named icon.See
fromIconName(java.lang.String)for details.- Parameters:
iconName- an icon name
-
setFromPaintable
- Parameters:
paintable- aGdkPaintable
-
setFromPixbuf
Deprecated.UsesetFromPaintable(org.gnome.gdk.Paintable)insteadSets aGtkImageto show aGdkPixbuf.See
fromPixbuf(org.gnome.gdkpixbuf.Pixbuf)for details.Note: This is a helper for
setFromPaintable(org.gnome.gdk.Paintable), and you can't get back the exact pixbuf once this is called, only a paintable.- Parameters:
pixbuf- aGdkPixbuforNULL
-
setFromResource
Sets aGtkImageto show a resource.See
fromResource(java.lang.String)for details.- Parameters:
resourcePath- a resource path
-
setIconSize
Suggests an icon size to the theme for named icons.- Parameters:
iconSize- the new icon size
-
setPixelSize
public void setPixelSize(int pixelSize) Sets the pixel size to use for named icons.If the pixel size is set to a value != -1, it is used instead of the icon size set by
setIconSize(org.gnome.gtk.IconSize).- Parameters:
pixelSize- the new pixel size
-
builder
AImage.Builderobject constructs aImagewith the specified properties. Use the variousset...()methods to set properties, and finish construction withImage.Builder.build().- Returns:
- the builder object
-
fromPaintable(org.gnome.gdk.Paintable)andTexture.forPixbuf(org.gnome.gdkpixbuf.Pixbuf)instead