Module io.github.stanio.xbrz.awt
Package io.github.stanio.xbrz.awt.util
Class MultiResolutionCachedImage
java.lang.Object
java.awt.Image
java.awt.image.AbstractMultiResolutionImage
io.github.stanio.xbrz.awt.util.BaseMultiResolutionImage
io.github.stanio.xbrz.awt.util.MultiResolutionCachedImage
- All Implemented Interfaces:
MultiResolutionImage
A
MultiResolutionImage
that caches resolution variants as they
get produced.- Implementation Note:
- Caches at most 4 variants. This should possibly cover the
most common scenario of displaying the same image (f.e. an icon)
on two monitors with different scaling factors
(
GraphicsConfiguration
s).
-
Field Summary
Fields inherited from class io.github.stanio.xbrz.awt.util.BaseMultiResolutionImage
baseHeight, baseWidth
Fields inherited from class java.awt.Image
accelerationPriority, SCALE_AREA_AVERAGING, SCALE_DEFAULT, SCALE_FAST, SCALE_REPLICATE, SCALE_SMOOTH, UndefinedProperty
-
Constructor Summary
ConstructorDescriptionMultiResolutionCachedImage
(int baseWidth, int baseHeight) Constructs a newMultiResolutionCachedImage
of the given base width and height, and resolution variant producer function. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Image
createResolutionVariant
(int width, int height) getResolutionVariant
(double destWidth, double destHeight) Gets a specific image that is the best variant to represent this logical image at the indicated size.This implementation returns a singleton list containing thebaseImage
.static Image
map
(MultiResolutionImage mrImage, Function<Image, Image> mapper) Maps the resolution variants of the given multi-resolution image using the given mapper function.static MultiResolutionCachedImage
of
(int baseWidth, int baseHeight, BiFunction<Integer, Integer, Image> variantProducer) static MultiResolutionCachedImage
withProducer
(int baseWidth, int baseHeight, BiFunction<Integer, Integer, Image> variantProducer) Methods inherited from class io.github.stanio.xbrz.awt.util.BaseMultiResolutionImage
getBaseImage, getHeight, getProperty, getScaledInstance, getWidth, preloadDimensions
Methods inherited from class java.awt.image.AbstractMultiResolutionImage
getGraphics, getSource
Methods inherited from class java.awt.Image
flush, getAccelerationPriority, getCapabilities, setAccelerationPriority
-
Constructor Details
-
MultiResolutionCachedImage
public MultiResolutionCachedImage(int baseWidth, int baseHeight) Constructs a newMultiResolutionCachedImage
of the given base width and height, and resolution variant producer function.- Parameters:
baseWidth
- the user-space logical with of the imagebaseHeight
- the user-space logical height of the image
-
-
Method Details
-
of
public static MultiResolutionCachedImage of(int baseWidth, int baseHeight, BiFunction<Integer, Integer, Image> variantProducer) -
withProducer
public static MultiResolutionCachedImage withProducer(int baseWidth, int baseHeight, BiFunction<Integer, Integer, Image> variantProducer) -
map
-
map
Maps the resolution variants of the given multi-resolution image using the given mapper function.Sample usage:
public static Image createDisabledImage(Image image) { if (i instanceof MultiResolutionImage) { return MultiResolutionCachedImage .map((MultiResolutionImage) image, (img) -> createDisabledImageImpl(img)); } return createDisabledImageImpl(image); } private static Image createDisabledImageImpl(Image image) { GrayFilter filter = new GrayFilter(true, 50); ImageProducer producer = new FilteredImageSource(image.getSource(), filter); return Toolkit.getDefaultToolkit().createImage(producer); }
-
getResolutionVariant
Description copied from interface:java.awt.image.MultiResolutionImage
Gets a specific image that is the best variant to represent this logical image at the indicated size.- Specified by:
getResolutionVariant
in interfaceMultiResolutionImage
- Specified by:
getResolutionVariant
in classBaseMultiResolutionImage
- Parameters:
destWidth
- the width of the destination image, in pixels.destHeight
- the height of the destination image, in pixels.- Returns:
- image resolution variant.
-
createResolutionVariant
-
getResolutionVariants
Description copied from class:BaseMultiResolutionImage
This implementation returns a singleton list containing thebaseImage
.- Specified by:
getResolutionVariants
in interfaceMultiResolutionImage
- Overrides:
getResolutionVariants
in classBaseMultiResolutionImage
- Returns:
- list of resolution variants.
-