java.awt.image.BaseMultiResolutionImage#java.awt.image.MultiResolutionImage源码实例Demo

下面列出了java.awt.image.BaseMultiResolutionImage#java.awt.image.MultiResolutionImage 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk9   文件: MultiResolutionImageTest.java
static void testToolkitMultiResolutionImageLoad(Image image)
    throws Exception {

    MediaTracker tracker = new MediaTracker(new JPanel());
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    if (tracker.isErrorAny()) {
        throw new RuntimeException("Error during image loading");
    }
    tracker.removeImage(image, 0);

    testImageLoaded(image);

    int w = image.getWidth(null);
    int h = image.getHeight(null);

    Image resolutionVariant = ((MultiResolutionImage) image)
        .getResolutionVariant(2 * w, 2 * h);

    if (image == resolutionVariant) {
        throw new RuntimeException("Resolution variant is not loaded");
    }

    testImageLoaded(resolutionVariant);
}
 
源代码2 项目: openjdk-jdk9   文件: MultiResolutionImageTest.java
static void testToolkitMultiResolutionImageChache(String fileName,
    URL url) {

    Image img1 = Toolkit.getDefaultToolkit().getImage(fileName);
    if (!(img1 instanceof MultiResolutionImage)) {
        throw new RuntimeException("Not a MultiResolutionImage");
    }

    Image img2 = Toolkit.getDefaultToolkit().getImage(fileName);
    if (img1 != img2) {
        throw new RuntimeException("Image is not cached");
    }

    img1 = Toolkit.getDefaultToolkit().getImage(url);
    if (!(img1 instanceof MultiResolutionImage)) {
        throw new RuntimeException("Not a MultiResolutionImage");
    }

    img2 = Toolkit.getDefaultToolkit().getImage(url);
    if (img1 != img2) {
        throw new RuntimeException("Image is not cached");
    }
}
 
源代码3 项目: jdk8u_jdk   文件: MultiResolutionImageTest.java
static void testToolkitMultiResolutionImageLoad(Image image)
    throws Exception {

    MediaTracker tracker = new MediaTracker(new JPanel());
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    if (tracker.isErrorAny()) {
        throw new RuntimeException("Error during image loading");
    }
    tracker.removeImage(image, 0);

    testImageLoaded(image);

    int w = image.getWidth(null);
    int h = image.getHeight(null);

    Image resolutionVariant = ((MultiResolutionImage) image)
        .getResolutionVariant(2 * w, 2 * h);

    if (image == resolutionVariant) {
        throw new RuntimeException("Resolution variant is not loaded");
    }

    testImageLoaded(resolutionVariant);
}
 
源代码4 项目: jdk8u_jdk   文件: MultiResolutionImageTest.java
static void testToolkitMultiResolutionImageChache(String fileName,
    URL url) {

    Image img1 = Toolkit.getDefaultToolkit().getImage(fileName);
    if (!(img1 instanceof MultiResolutionImage)) {
        throw new RuntimeException("Not a MultiResolutionImage");
    }

    Image img2 = Toolkit.getDefaultToolkit().getImage(fileName);
    if (img1 != img2) {
        throw new RuntimeException("Image is not cached");
    }

    img1 = Toolkit.getDefaultToolkit().getImage(url);
    if (!(img1 instanceof MultiResolutionImage)) {
        throw new RuntimeException("Not a MultiResolutionImage");
    }

    img2 = Toolkit.getDefaultToolkit().getImage(url);
    if (img1 != img2) {
        throw new RuntimeException("Image is not cached");
    }
}
 
源代码5 项目: tutorials   文件: MultiResultionImageUnitTest.java
@Test
public void baseMultiResImageTest() {
    int baseIndex = 1;
    int length = 4;
    BufferedImage[] resolutionVariants = new BufferedImage[length];
    for (int i = 0; i < length; i++) {
        resolutionVariants[i] = createImage(i);
    }
    MultiResolutionImage bmrImage = new BaseMultiResolutionImage(baseIndex, resolutionVariants);
    List<Image> rvImageList = bmrImage.getResolutionVariants();
    assertEquals("MultiResoltion Image shoudl contain the same number of resolution variants!", rvImageList.size(), length);

    for (int i = 0; i < length; i++) {
        int imageSize = getSize(i);
        Image testRVImage = bmrImage.getResolutionVariant(imageSize, imageSize);
        assertSame("Images should be the same", testRVImage, resolutionVariants[i]);
    }

}
 
源代码6 项目: FlatLaf   文件: MultiResolutionImageSupport.java
@Override
public List<Image> getResolutionVariants() {
	List<Image> variants = ((MultiResolutionImage)mrImage).getResolutionVariants();
	List<Image> mappedVariants = new ArrayList<>();
	for( Image image : variants )
		mappedVariants.add( mapAndCacheImage( image ) );
	return mappedVariants;
}
 
源代码7 项目: Bytecoder   文件: SunToolkit.java
protected Image getImageWithResolutionVariant(String fileName,
        String resolutionVariantName) {
    synchronized (fileImgCache) {
        Image image = getImageFromHash(this, fileName);
        if (image instanceof MultiResolutionImage) {
            return image;
        }
        Image resolutionVariant = getImageFromHash(this, resolutionVariantName);
        image = createImageWithResolutionVariant(image, resolutionVariant);
        fileImgCache.put(fileName, image);
        return image;
    }
}
 
源代码8 项目: Bytecoder   文件: SunToolkit.java
protected Image getImageWithResolutionVariant(URL url,
        URL resolutionVariantURL) {
    synchronized (urlImgCache) {
        Image image = getImageFromHash(this, url);
        if (image instanceof MultiResolutionImage) {
            return image;
        }
        Image resolutionVariant = getImageFromHash(this, resolutionVariantURL);
        image = createImageWithResolutionVariant(image, resolutionVariant);
        String key = url.toString();
        urlImgCache.put(key, image);
        return image;
    }
}
 
源代码9 项目: Bytecoder   文件: MultiResolutionCachedImage.java
public static Image map(MultiResolutionImage mrImage,
                        Function<Image, Image> mapper) {

    if (mrImage instanceof MultiResolutionToolkitImage) {
        MultiResolutionToolkitImage mrtImage =
                (MultiResolutionToolkitImage) mrImage;
        return MultiResolutionToolkitImage.map(mrtImage, mapper);
    }

    BiFunction<Integer, Integer, Image> sizeMapper
            = (w, h) -> mapper.apply(mrImage.getResolutionVariant(w, h));

    if (mrImage instanceof MultiResolutionCachedImage) {
        MultiResolutionCachedImage mrcImage
                = (MultiResolutionCachedImage) mrImage;

        return new MultiResolutionCachedImage(mrcImage.baseImageWidth,
                                              mrcImage.baseImageHeight,
                                              mrcImage.sizes,
                                              sizeMapper,
                                              false);
    }

    Image image = (Image) mrImage;
    int width = image.getWidth(null);
    int height = image.getHeight(null);
    return new MultiResolutionCachedImage(width, height, sizeMapper);
}
 
源代码10 项目: openjdk-jdk9   文件: SunToolkit.java
protected Image getImageWithResolutionVariant(String fileName,
        String resolutionVariantName) {
    synchronized (fileImgCache) {
        Image image = getImageFromHash(this, fileName);
        if (image instanceof MultiResolutionImage) {
            return image;
        }
        Image resolutionVariant = getImageFromHash(this, resolutionVariantName);
        image = createImageWithResolutionVariant(image, resolutionVariant);
        fileImgCache.put(fileName, image);
        return image;
    }
}
 
源代码11 项目: openjdk-jdk9   文件: SunToolkit.java
protected Image getImageWithResolutionVariant(URL url,
        URL resolutionVariantURL) {
    synchronized (urlImgCache) {
        Image image = getImageFromHash(this, url);
        if (image instanceof MultiResolutionImage) {
            return image;
        }
        Image resolutionVariant = getImageFromHash(this, resolutionVariantURL);
        image = createImageWithResolutionVariant(image, resolutionVariant);
        String key = url.toString();
        urlImgCache.put(key, image);
        return image;
    }
}
 
源代码12 项目: openjdk-jdk9   文件: MultiResolutionCachedImage.java
public static Image map(MultiResolutionImage mrImage,
                        Function<Image, Image> mapper) {

    if (mrImage instanceof MultiResolutionToolkitImage) {
        MultiResolutionToolkitImage mrtImage =
                (MultiResolutionToolkitImage) mrImage;
        return MultiResolutionToolkitImage.map(mrtImage, mapper);
    }

    BiFunction<Integer, Integer, Image> sizeMapper
            = (w, h) -> mapper.apply(mrImage.getResolutionVariant(w, h));

    if (mrImage instanceof MultiResolutionCachedImage) {
        MultiResolutionCachedImage mrcImage
                = (MultiResolutionCachedImage) mrImage;

        return new MultiResolutionCachedImage(mrcImage.baseImageWidth,
                                              mrcImage.baseImageHeight,
                                              mrcImage.sizes,
                                              sizeMapper,
                                              false);
    }

    Image image = (Image) mrImage;
    int width = image.getWidth(null);
    int height = image.getHeight(null);
    return new MultiResolutionCachedImage(width, height, sizeMapper);
}
 
源代码13 项目: openjdk-jdk9   文件: CImage.java
private CImage createFromImage(final Image image, final boolean prepareImage) {
    if (image instanceof MultiResolutionImage) {
        List<Image> resolutionVariants
                = ((MultiResolutionImage) image).getResolutionVariants();
        return createFromImages(resolutionVariants, prepareImage);
    }

    int[] buffer = imageToArray(image, prepareImage);
    if (buffer == null) {
        return null;
    }
    return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
 
public static void main(String[] args) throws Exception {

        Image baseMRImage = new BaseMultiResolutionImage(createImage(1),
                                                         createImage(2));
        testMRDisabledImage(baseMRImage);

        saveImages();
        Image toolkitMRImage = Toolkit.getDefaultToolkit().getImage(IMAGE_NAME_1X);

        if (toolkitMRImage instanceof MultiResolutionImage) {
            testMRDisabledImage(toolkitMRImage);
        }
    }
 
public static void main(String[] args) throws Exception {

        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
            return;
        }

        String icon = "NSImage://NSApplicationIcon";
        final Image image = Toolkit.getDefaultToolkit().getImage(icon);

        if (!(image instanceof MultiResolutionImage)) {
            throw new RuntimeException("Icon does not have resolution variants!");
        }

        MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;

        int width = 0;
        int height = 0;

        for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
            int rvWidth = resolutionVariant.getWidth(null);
            int rvHeight = resolutionVariant.getHeight(null);
            if (rvWidth < width || rvHeight < height) {
                throw new RuntimeException("Resolution variants are not sorted!");
            }
            width = rvWidth;
            height = rvHeight;
        }
    }
 
static void testRVSizes() {

        int imageSize = getSize(1);

        double[][] sizeArray = {
            {-imageSize, imageSize},
            {2 * imageSize, -2 * imageSize},
            {Double.POSITIVE_INFINITY, imageSize},
            {Double.POSITIVE_INFINITY, -imageSize},
            {imageSize, Double.NEGATIVE_INFINITY},
            {-imageSize, Double.NEGATIVE_INFINITY},
            {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY},
            {Double.NaN, imageSize},
            {imageSize, Double.NaN},
            {Double.NaN, Double.NaN},
            {Double.POSITIVE_INFINITY, Double.NaN}
        };

        for (double[] sizes : sizeArray) {
            try {
                MultiResolutionImage mrImage = new BaseMultiResolutionImage(
                        0, createRVImage(0), createRVImage(1));
                mrImage.getResolutionVariant(sizes[0], sizes[1]);
            } catch (IllegalArgumentException ignored) {
                continue;
            }

            throw new RuntimeException("IllegalArgumentException is not thrown!");
        }
    }
 
源代码17 项目: openjdk-jdk9   文件: BadHiDPIIcon.java
private static BufferedImage getBufferedImage(Image image) {
    if (image instanceof MultiResolutionImage) {
        MultiResolutionImage mrImage = (MultiResolutionImage) image;
        return (BufferedImage) mrImage.getResolutionVariant(32, 32);
    }
    return (BufferedImage) image;
}
 
源代码18 项目: jdk8u_jdk   文件: SunToolkit.java
protected Image getImageWithResolutionVariant(String fileName,
        String resolutionVariantName) {
    synchronized (fileImgCache) {
        Image image = getImageFromHash(this, fileName);
        if (image instanceof MultiResolutionImage) {
            return image;
        }
        Image resolutionVariant = getImageFromHash(this, resolutionVariantName);
        image = createImageWithResolutionVariant(image, resolutionVariant);
        fileImgCache.put(fileName, image);
        return image;
    }
}
 
源代码19 项目: jdk8u_jdk   文件: SunToolkit.java
protected Image getImageWithResolutionVariant(URL url,
        URL resolutionVariantURL) {
    synchronized (urlImgCache) {
        Image image = getImageFromHash(this, url);
        if (image instanceof MultiResolutionImage) {
            return image;
        }
        Image resolutionVariant = getImageFromHash(this, resolutionVariantURL);
        image = createImageWithResolutionVariant(image, resolutionVariant);
        String key = url.toString();
        urlImgCache.put(key, image);
        return image;
    }
}
 
源代码20 项目: jdk8u_jdk   文件: CImage.java
private CImage createFromImage(final Image image, final boolean prepareImage) {
    if (image instanceof MultiResolutionImage) {
        List<Image> resolutionVariants
                = ((MultiResolutionImage) image).getResolutionVariants();
        return createFromImages(resolutionVariants, prepareImage);
    }

    int[] buffer = imageToArray(image, prepareImage);
    if (buffer == null) {
        return null;
    }
    return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
 
public static void main(String[] args) throws Exception {

        Image baseMRImage = new BaseMultiResolutionImage(createImage(1),
                                                         createImage(2));
        testMRDisabledImage(baseMRImage);

        saveImages();
        Image toolkitMRImage = Toolkit.getDefaultToolkit().getImage(IMAGE_NAME_1X);

        if (toolkitMRImage instanceof MultiResolutionImage) {
            testMRDisabledImage(toolkitMRImage);
        }
    }
 
public static void main(String[] args) throws Exception {

        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
            return;
        }

        String icon = "NSImage://NSApplicationIcon";
        final Image image = Toolkit.getDefaultToolkit().getImage(icon);

        if (!(image instanceof MultiResolutionImage)) {
            throw new RuntimeException("Icon does not have resolution variants!");
        }

        MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;

        int width = 0;
        int height = 0;

        for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
            int rvWidth = resolutionVariant.getWidth(null);
            int rvHeight = resolutionVariant.getHeight(null);
            if (rvWidth < width || rvHeight < height) {
                throw new RuntimeException("Resolution variants are not sorted!");
            }
            width = rvWidth;
            height = rvHeight;
        }
    }
 
源代码23 项目: jdk8u_jdk   文件: BaseMultiResolutionImageTest.java
static void testRVSizes() {

        int imageSize = getSize(1);

        double[][] sizeArray = {
            {-imageSize, imageSize},
            {2 * imageSize, -2 * imageSize},
            {Double.POSITIVE_INFINITY, imageSize},
            {Double.POSITIVE_INFINITY, -imageSize},
            {imageSize, Double.NEGATIVE_INFINITY},
            {-imageSize, Double.NEGATIVE_INFINITY},
            {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY},
            {Double.NaN, imageSize},
            {imageSize, Double.NaN},
            {Double.NaN, Double.NaN},
            {Double.POSITIVE_INFINITY, Double.NaN}
        };

        for (double[] sizes : sizeArray) {
            try {
                MultiResolutionImage mrImage = new BaseMultiResolutionImage(
                        0, createRVImage(0), createRVImage(1));
                mrImage.getResolutionVariant(sizes[0], sizes[1]);
            } catch (IllegalArgumentException ignored) {
                continue;
            }

            throw new RuntimeException("IllegalArgumentException is not thrown!");
        }
    }
 
源代码24 项目: demo-java-x   文件: Images.java
public static void main(String[] args) throws IOException {
	MultiResolutionImage tokio = loadTokio();
	int desiredImageWidth = ThreadLocalRandom.current().nextInt(1500);
	Image variant = tokio.getResolutionVariant(desiredImageWidth, 1);

	System.out.printf("Width of image for %d: %d%n", desiredImageWidth, variant.getWidth(null));
}
 
源代码25 项目: demo-java-x   文件: Images.java
private static MultiResolutionImage loadTokio() throws IOException {
	List<Image> tokios = new ArrayList<>();
	for (String url : IMAGE_URLS) {
		tokios.add(ImageIO.read(new URL(url)));
	}
	return new BaseMultiResolutionImage(tokios.toArray(new Image[0]));
}
 
源代码26 项目: FlatLaf   文件: MultiResolutionImageSupport.java
public static boolean isMultiResolutionImage( Image image ) {
	return image instanceof MultiResolutionImage;
}
 
源代码27 项目: FlatLaf   文件: MultiResolutionImageSupport.java
public static Image map( Image image, Function<Image, Image> mapper ) {
	return image instanceof MultiResolutionImage
		? new MappedMultiResolutionImage( image, mapper )
		: mapper.apply( image );
}
 
源代码28 项目: FlatLaf   文件: MultiResolutionImageSupport.java
public static Image getResolutionVariant( Image image, int destImageWidth, int destImageHeight ) {
	return (image instanceof MultiResolutionImage)
		? ((MultiResolutionImage)image).getResolutionVariant( destImageWidth, destImageHeight )
		: image;
}
 
源代码29 项目: FlatLaf   文件: MultiResolutionImageSupport.java
public static List<Image> getResolutionVariants( Image image ) {
	return (image instanceof MultiResolutionImage)
		? ((MultiResolutionImage)image).getResolutionVariants()
		: Collections.singletonList( image );
}
 
源代码30 项目: FlatLaf   文件: MultiResolutionImageSupport.java
@Override
public Image getResolutionVariant( double destImageWidth, double destImageHeight ) {
	Image variant = ((MultiResolutionImage)mrImage).getResolutionVariant( destImageWidth, destImageHeight );
	return mapAndCacheImage( variant );
}