src/share/classes/sun/awt/image/MultiResolutionBufferedImage.java

Print this page

        

*** 32,63 **** import java.util.Arrays; import java.util.List; import java.util.function.Function; import java.util.function.BiFunction; import java.util.stream.Collectors; public class MultiResolutionBufferedImage extends BufferedImage implements MultiResolutionImage { private final BiFunction<Integer, Integer, Image> mapper; private final Dimension2D[] sizes; private int availableInfo; public MultiResolutionBufferedImage(Image baseImage, Dimension2D[] sizes, BiFunction<Integer, Integer, Image> mapper) { super(baseImage.getWidth(null), baseImage.getHeight(null), BufferedImage.TYPE_INT_ARGB_PRE); this.sizes = sizes; this.mapper = mapper; this.availableInfo = getInfo(baseImage); Graphics g = getGraphics(); g.drawImage(baseImage, 0, 0, null); g.dispose(); } @Override ! public Image getResolutionVariant(int width, int height) { int baseWidth = getWidth(); int baseHeight = getHeight(); if (baseWidth == width && baseHeight == height) { return this; --- 32,82 ---- import java.util.Arrays; import java.util.List; import java.util.function.Function; import java.util.function.BiFunction; import java.util.stream.Collectors; + import java.awt.image.MultiResolutionImage; public class MultiResolutionBufferedImage extends BufferedImage implements MultiResolutionImage { private final BiFunction<Integer, Integer, Image> mapper; private final Dimension2D[] sizes; + private final ImageResolutionHelper imageResolutionHelper; private int availableInfo; public MultiResolutionBufferedImage(Image baseImage, Dimension2D[] sizes, BiFunction<Integer, Integer, Image> mapper) { + this(baseImage, sizes, mapper, ImageResolutionHelperType.getPlatformHelper()); + } + + public MultiResolutionBufferedImage(Image baseImage, + Dimension2D[] sizes, BiFunction<Integer, Integer, Image> mapper, + ImageResolutionHelper imageResolutionHelper) { super(baseImage.getWidth(null), baseImage.getHeight(null), BufferedImage.TYPE_INT_ARGB_PRE); this.sizes = sizes; this.mapper = mapper; this.availableInfo = getInfo(baseImage); + this.imageResolutionHelper = imageResolutionHelper; Graphics g = getGraphics(); g.drawImage(baseImage, 0, 0, null); g.dispose(); } @Override ! public Image getResolutionVariant(float logicalDPIX, float logicalDPIY, ! float baseWidth, float baseHeight, float destWidth, float destHeight) { ! ! float hiDPIWidth = imageResolutionHelper.getHiDPISize(logicalDPIX, ! baseWidth, destWidth); ! float hiDPIHeight = imageResolutionHelper.getHiDPISize(logicalDPIY, ! baseHeight, destHeight); ! return getResolutionVariant((int) hiDPIWidth, (int) hiDPIHeight); ! } ! ! private Image getResolutionVariant(int width, int height) { int baseWidth = getWidth(); int baseHeight = getHeight(); if (baseWidth == width && baseHeight == height) { return this;