Class Image
- All Implemented Interfaces:
Proxy
,Accessible
,Buildable
,ConstraintTarget
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
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
Texture.fromFile(org.gnome.gio.File)
, 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_ACCESSIBLE_ROLE_IMG
role.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Image.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.WidgetClass, Widget.WidgetImpl
Nested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClass
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gtk.Accessible
Accessible.AccessibleImpl, Accessible.AccessibleInterface
Nested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.BuildableIface, Buildable.BuildableImpl
Nested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTargetImpl, ConstraintTarget.ConstraintTargetInterface
-
Constructor Summary
ConstructorDescriptionImage()
Creates a new emptyGtkImage
widget.Image
(MemorySegment address) Create a Image proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected Image
asParent()
Returns this instance as if it were its parent type.static Image.Builder
<? extends Image.Builder> builder()
AImage.Builder
object constructs aImage
with the specified properties.void
clear()
Resets the image to be empty.static Image
Creates a newGtkImage
displaying the filefilename
.static Image
Creates aGtkImage
displaying an icon from the current icon theme.static Image
fromIconName
(@Nullable String iconName) Creates aGtkImage
displaying an icon from the current icon theme.static Image
fromPaintable
(@Nullable Paintable paintable) Creates a newGtkImage
displayingpaintable
.static Image
fromPixbuf
(@Nullable Pixbuf pixbuf) Deprecated.static Image
fromResource
(String resourcePath) Creates a newGtkImage
displaying the resource fileresourcePath
.getGicon()
Gets theGIcon
being displayed by theGtkImage
.Gets the icon name and size being displayed by theGtkImage
.Gets the icon size used by the this Image when rendering icons.Gets the imageGdkPaintable
being displayed by theGtkImage
.int
Gets the pixel size used for named icons.Gets the type of representation being used by theGtkImage
to store image data.static Type
getType()
Get the GType of the Image classvoid
setFromFile
(@Nullable String filename) Sets aGtkImage
to show a file.void
setFromGicon
(Icon icon) Sets aGtkImage
to show aGIcon
.void
setFromIconName
(@Nullable String iconName) Sets aGtkImage
to show a named icon.void
setFromPaintable
(@Nullable Paintable paintable) Sets aGtkImage
to show aGdkPaintable
.void
setFromPixbuf
(@Nullable Pixbuf pixbuf) Deprecated.UsesetFromPaintable(org.gnome.gdk.Paintable)
insteadvoid
setFromResource
(@Nullable String resourcePath) Sets aGtkImage
to show a resource.void
setIconSize
(IconSize iconSize) Suggests an icon size to the theme for named icons.void
setPixelSize
(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, 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, 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, unsetStateFlags
Methods 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, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.gnome.gtk.Accessible
announce, getAccessibleParent, getAccessibleRole, getAtContext, getBounds, getFirstAccessibleChild, getNextAccessibleSibling, getPlatformState, resetProperty, resetRelation, resetState, setAccessibleParent, updateNextAccessibleSibling, updateProperty, updateRelation, updateState
Methods 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 emptyGtkImage
widget.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, 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 newGtkImage
displaying the filefilename
.If the file isn’t found or can’t be loaded, the resulting
GtkImage
will display a “broken image” icon. This function never returnsnull
, it always returns a validGtkImage
widget.If you need to detect failures to load the file, use
Texture.fromFile(org.gnome.gio.File)
to load the file yourself, then create theGtkImage
from 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 aGtkImage
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.
- Parameters:
icon
- an icon- Returns:
- a new
GtkImage
displaying the themed icon
-
fromIconName
Creates aGtkImage
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.
- Parameters:
iconName
- an icon name- Returns:
- a new
GtkImage
displaying the themed icon
-
fromPaintable
Creates a newGtkImage
displayingpaintable
.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 thepaintable
and update its size and contents in response to it.- Parameters:
paintable
- aGdkPaintable
- Returns:
- a new
GtkImage
-
fromPixbuf
Deprecated.Creates a newGtkImage
displayingpixbuf
.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
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
GtkImage
from the pixbuf. TheGtkImage
created 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 newGtkImage
displaying the resource fileresourcePath
.If the file isn’t found or can’t be loaded, the resulting
GtkImage
will display a “broken image” icon. This function never returnsnull
, it always returns a validGtkImage
widget.If you need to detect failures to load the file, use
Pixbuf.fromFile(java.lang.String)
to load the file yourself, then create theGtkImage
from the pixbuf.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 theGIcon
being displayed by theGtkImage
.The storage type of the image must be
ImageType.EMPTY
orImageType.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.EMPTY
orImageType.ICON_NAME
(seegetStorageType()
). The returned string is owned by theGtkImage
and 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 imageGdkPaintable
being displayed by theGtkImage
.The storage type of the image must be
ImageType.EMPTY
orImageType.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 theGtkImage
to store image data.If the
GtkImage
has no image data, the return value will beImageType.EMPTY
.- Returns:
- image representation being used
-
setFromFile
Sets aGtkImage
to show a file.See
fromFile(java.lang.String)
for details.- Parameters:
filename
- a filename
-
setFromGicon
- Parameters:
icon
- an icon
-
setFromIconName
Sets aGtkImage
to 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 aGtkImage
to 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
- aGdkPixbuf
orNULL
-
setFromResource
Sets aGtkImage
to 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
setFromIconName(java.lang.String)
.- Parameters:
pixelSize
- the new pixel size
-
builder
AImage.Builder
object constructs aImage
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withImage.Builder.build()
.
-
fromPaintable(org.gnome.gdk.Paintable)
andTexture.forPixbuf(org.gnome.gdkpixbuf.Pixbuf)
instead