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
(
GraphicsConfigurations).
-
Field Summary
Fields inherited from class io.github.stanio.xbrz.awt.util.BaseMultiResolutionImage
baseHeight, baseWidthFields inherited from class java.awt.Image
accelerationPriority, SCALE_AREA_AVERAGING, SCALE_DEFAULT, SCALE_FAST, SCALE_REPLICATE, SCALE_SMOOTH, UndefinedProperty -
Constructor Summary
ConstructorsConstructorDescriptionMultiResolutionCachedImage(int baseWidth, int baseHeight) Constructs a newMultiResolutionCachedImageof the given base width and height, and resolution variant producer function. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract ImagecreateResolutionVariant(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 Imagemap(MultiResolutionImage mrImage, Function<Image, Image> mapper) Maps the resolution variants of the given multi-resolution image using the given mapper function.static MultiResolutionCachedImageof(int baseWidth, int baseHeight, BiFunction<Integer, Integer, Image> variantProducer) static MultiResolutionCachedImagewithProducer(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, preloadDimensionsMethods inherited from class java.awt.image.AbstractMultiResolutionImage
getGraphics, getSourceMethods inherited from class java.awt.Image
flush, getAccelerationPriority, getCapabilities, setAccelerationPriority
-
Constructor Details
-
MultiResolutionCachedImage
public MultiResolutionCachedImage(int baseWidth, int baseHeight) Constructs a newMultiResolutionCachedImageof 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.MultiResolutionImageGets a specific image that is the best variant to represent this logical image at the indicated size.- Specified by:
getResolutionVariantin interfaceMultiResolutionImage- Specified by:
getResolutionVariantin 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:BaseMultiResolutionImageThis implementation returns a singleton list containing thebaseImage.- Specified by:
getResolutionVariantsin interfaceMultiResolutionImage- Overrides:
getResolutionVariantsin classBaseMultiResolutionImage- Returns:
- list of resolution variants.
-