Class MultiResolutionImageSupport
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Image
Creates a multi-resolution image for the given dimensions.static Image
Creates a multi-resolution image from the given resolution variants.static Image
getResolutionVariant
(Image image, int destImageWidth, int destImageHeight) Get the image variant that best matches the given width and height.getResolutionVariants
(Image image) Get a list of all resolution variants.static boolean
Checks whether multi-resolution image support is available.static boolean
isMultiResolutionImage
(Image image) Checks whether the given image is a multi-resolution image that implements the interfacejava.awt.image.MultiResolutionImage
.static Image
Creates a multi-resolution image that maps images from another multi-resolution image using the given mapper function.
-
Constructor Details
-
MultiResolutionImageSupport
public MultiResolutionImageSupport()
-
-
Method Details
-
isAvailable
public static boolean isAvailable()Checks whether multi-resolution image support is available.- Returns:
true
when running on Java 9 or later;false
on Java 8
-
isMultiResolutionImage
Checks whether the given image is a multi-resolution image that implements the interfacejava.awt.image.MultiResolutionImage
. -
create
Creates a multi-resolution image from the given resolution variants.- Parameters:
baseImageIndex
- index of the base image in the resolution variants arrayresolutionVariants
- image resolution variants (sorted by size; smallest first)- Returns:
- a multi-resolution image on Java 9 or later; the base image on Java 8
-
create
public static Image create(int baseImageIndex, Dimension[] dimensions, Function<Dimension, Image> producer) Creates a multi-resolution image for the given dimensions. Initially the image does not contain any image data. The real images are created (and cached) on demand by invoking the given producer function.The given dimensions array is only used for
getResolutionVariants(Image)
. The producer function may be invoked with any dimension (that is not contained in dimensions array) and is expected to produce an image for the passed in dimension.- Parameters:
baseImageIndex
- index of the base image in the dimensions arraydimensions
- dimensions of resolution variants (sorted by size; smallest first)producer
- producer function that creates a real image for the requested size- Returns:
- a multi-resolution image on Java 9 or later; the base image on Java 8
-
map
Creates a multi-resolution image that maps images from another multi-resolution image using the given mapper function.Can be used to apply filter to multi-resolution images on demand. E.g. passed in image is for "enabled" state and mapper function creates images for "disabled" state.
- Parameters:
image
- a multi-resolution image that is mapped using the given mapper functionmapper
- mapper function that maps a single resolution variant to a new image (e.g. applying a filter)- Returns:
- a multi-resolution image on Java 9 or later; a mapped image on Java 8
-
getResolutionVariant
Get the image variant that best matches the given width and height.If the given image is a multi-resolution image then invokes
java.awt.image.MultiResolutionImage.getResolutionVariant(destImageWidth, destImageHeight)
. Otherwise, returns the given image. -
getResolutionVariants
Get a list of all resolution variants.If the given image is a multi-resolution image then invokes
java.awt.image.MultiResolutionImage.getResolutionVariants()
. Otherwise, returns a list containing only the given image.
-