Class Picture
- All Implemented Interfaces:
Accessible,Buildable,ConstraintTarget,Proxy
GdkPaintable.
Many convenience functions are provided to make pictures simple to use. For example, if you want to load an image from a file, and then display it, there’s a convenience function to do this:
GtkWidget *widget = gtk_picture_new_for_filename ("myfile.png");
If the file isn’t loaded successfully, the picture 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
and image loading framework such as libglycin, then create the GtkPicture
with forPaintable(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 for details.
In this case, forResource(java.lang.String) and
setResource(java.lang.String) should be used.
GtkPicture displays an image at its natural size. See Image
if you want to display a fixed-size image, such as an icon.
Sizing the paintable
You can influence how the paintable is displayed inside the GtkPicture
by changing Gtk.Picture:content-fit. See Gtk.ContentFit
for details. Gtk.Picture:can-shrink can be unset to make sure
that paintables are never made smaller than their ideal size - but
be careful if you do not know the size of the paintable in use (like
when displaying user-loaded images). This can easily cause the picture to
grow larger than the screen. And Gtk.Widget:halign and
Gtk.Widget:valign can be used to make sure the paintable doesn't
fill all available space but is instead displayed at its original size.
CSS nodes
GtkPicture has a single CSS node with the name picture.
Accessibility
GtkPicture uses the Gtk.AccessibleRole.img role.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPicture.Builder<B extends Picture.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested 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
ConstructorsConstructorDescriptionPicture()Creates a new Picture.Picture(MemorySegment address) Create a Picture proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected PictureasParent()Returns this instance as if it were its parent type.static Picture.Builder<? extends Picture.Builder> builder()APicture.Builderobject constructs aPicturewith the specified properties.static PictureCreates a newGtkPicturedisplaying the givenfile.static PictureforFilename(@Nullable String filename) Creates a newGtkPicturedisplaying the filefilename.static PictureforPaintable(@Nullable Paintable paintable) Creates a newGtkPicturedisplayingpaintable.static PictureDeprecated.static PictureforResource(@Nullable String resourcePath) Creates a newGtkPicturedisplaying the resource atresourcePath.@Nullable StringGets the alternative textual description of the picture.booleanReturns whether theGtkPicturerespects its contents size.Returns the fit mode for the content of theGtkPicture.@Nullable FilegetFile()Gets theGFilecurrently displayed if this Picture is displaying a file.booleanDeprecated.UsegetContentFit()instead.@Nullable PaintableGets theGdkPaintablebeing displayed by theGtkPicture.static @Nullable TypegetType()Get the GType of the Picture classvoidsetAlternativeText(@Nullable String alternativeText) Sets an alternative textual description for the picture contents.voidsetCanShrink(boolean canShrink) If set totrue, the this Picture can be made smaller than its contents.voidsetContentFit(ContentFit contentFit) Sets how the content should be resized to fit theGtkPicture.voidMakes this Picture load and displayfile.voidsetFilename(@Nullable String filename) Makes this Picture load and display the givenfilename.voidsetKeepAspectRatio(boolean keepAspectRatio) Deprecated.UsesetContentFit(org.gnome.gtk.ContentFit)instead.voidsetPaintable(@Nullable Paintable paintable) Makes this Picture display the givenpaintable.voidDeprecated.UsesetPaintable(org.gnome.gdk.Paintable)insteadvoidsetResource(@Nullable String resourcePath) Makes this Picture load and display the resource at the givenresourcePath.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
-
Picture
Create a Picture proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Picture
public Picture()Creates a new Picture.
-
-
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. -
forFile
Creates a newGtkPicturedisplaying the givenfile.If the file isn’t found or can’t be loaded, the resulting
GtkPictureis empty.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
GtkPicturefrom the texture.- Parameters:
file- aGFile- Returns:
- a new
GtkPicture
-
forFilename
Creates a newGtkPicturedisplaying the filefilename.This is a utility function that calls
forFile(org.gnome.gio.File). See that function for details.- Parameters:
filename- a filename- Returns:
- a new
GtkPicture
-
forPaintable
-
forPixbuf
Deprecated.Creates a newGtkPicturedisplayingpixbuf.This is a utility function that calls
forPaintable(org.gnome.gdk.Paintable), See that function for details.The pixbuf must not be modified after passing it to this function.
- Parameters:
pixbuf- aGdkPixbuf- Returns:
- a new
GtkPicture
-
forResource
Creates a newGtkPicturedisplaying the resource atresourcePath.This is a utility function that calls
forFile(org.gnome.gio.File). See that function for details.- Parameters:
resourcePath- resource path to play back- Returns:
- a new
GtkPicture
-
getAlternativeText
Gets the alternative textual description of the picture.The returned string will be
nullif the picture cannot be described textually.- Returns:
- the alternative textual description of
self.
-
getCanShrink
public boolean getCanShrink()Returns whether theGtkPicturerespects its contents size.- Returns:
trueif the picture can be made smaller than its contents
-
getContentFit
Returns the fit mode for the content of theGtkPicture.See
Gtk.ContentFitfor details.- Returns:
- the content fit mode
- Since:
- 4.8
-
getFile
Gets theGFilecurrently displayed if this Picture is displaying a file.If this Picture is not displaying a file, for example when
setPaintable(org.gnome.gdk.Paintable)was used, thennullis returned.- Returns:
- The
GFiledisplayed byself.
-
getKeepAspectRatio
Deprecated.UsegetContentFit()instead. This will now returnFALSEonly ifGtk.Picture:content-fitisGTK_CONTENT_FIT_FILL. ReturnsTRUEotherwise.Returns whether theGtkPicturepreserves its contents aspect ratio.- Returns:
trueif the self tries to keep the contents' aspect ratio
-
getPaintable
Gets theGdkPaintablebeing displayed by theGtkPicture.- Returns:
- the displayed paintable
-
setAlternativeText
Sets an alternative textual description for the picture contents.It is equivalent to the "alt" attribute for images on websites.
This text will be made available to accessibility tools.
If the picture cannot be described textually, set this property to
null.- Parameters:
alternativeText- a textual description of the contents
-
setCanShrink
public void setCanShrink(boolean canShrink) If set totrue, the this Picture can be made smaller than its contents.The contents will then be scaled down when rendering.
If you want to still force a minimum size manually, consider using
Widget.setSizeRequest(int, int).Also of note is that a similar function for growing does not exist because the grow behavior can be controlled via
Widget.setHalign(org.gnome.gtk.Align)andWidget.setValign(org.gnome.gtk.Align).- Parameters:
canShrink- if this Picture can be made smaller than its contents
-
setContentFit
Sets how the content should be resized to fit theGtkPicture.See
Gtk.ContentFitfor details.- Parameters:
contentFit- the content fit mode- Since:
- 4.8
-
setFile
Makes this Picture load and displayfile.See
forFile(org.gnome.gio.File)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:
file- aGFile
-
setFilename
Makes this Picture load and display the givenfilename.This is a utility function that calls
setFile(org.gnome.gio.File).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- the filename to play
-
setKeepAspectRatio
Deprecated.UsesetContentFit(org.gnome.gtk.ContentFit)instead. If still used, this method will always set theGtk.Picture:content-fitproperty toGTK_CONTENT_FIT_CONTAINifkeepAspectRatiois true, otherwise it will set it toGTK_CONTENT_FIT_FILL.If set totrue, the this Picture will render its contents according to their aspect ratio.That means that empty space may show up at the top/bottom or left/right of
self.If set to
falseor if the contents provide no aspect ratio, the contents will be stretched over the picture's whole area.- Parameters:
keepAspectRatio- whether to keep aspect ratio
-
setPaintable
Makes this Picture display the givenpaintable.If
paintableisNULL, nothing will be displayed.See
forPaintable(org.gnome.gdk.Paintable)for details.- Parameters:
paintable- aGdkPaintable
-
setPixbuf
Deprecated.UsesetPaintable(org.gnome.gdk.Paintable)insteadSets aGtkPictureto show aGdkPixbuf.See
forPixbuf(org.gnome.gdkpixbuf.Pixbuf)for details.This is a utility function that calls
setPaintable(org.gnome.gdk.Paintable).- Parameters:
pixbuf- aGdkPixbuf
-
setResource
Makes this Picture load and display the resource at the givenresourcePath.This is a utility function that calls
setFile(org.gnome.gio.File).- Parameters:
resourcePath- the resource to set
-
builder
APicture.Builderobject constructs aPicturewith the specified properties. Use the variousset...()methods to set properties, and finish construction withPicture.Builder.build().- Returns:
- the builder object
-
forPaintable(org.gnome.gdk.Paintable)andTexture.forPixbuf(org.gnome.gdkpixbuf.Pixbuf)instead