Search in sources :

Example 6 with java.awt.image

use of java.awt.image in project jdk8u_jdk by JetBrains.

the class MultiResolutionToolkitImageTest method testToolkitMultiResolutionImageLoad.

static void testToolkitMultiResolutionImageLoad() throws Exception {
    File imageFile = new File(IMAGE_NAME_1X);
    String fileName = imageFile.getAbsolutePath();
    Image image = Toolkit.getDefaultToolkit().getImage(fileName);
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    toolkit.prepareImage(image, -1, -1, new LoadImageObserver());
    final long time = WAIT_TIME + System.currentTimeMillis();
    while ((!isImageLoaded || !isRVObserverCalled) && System.currentTimeMillis() < time) {
        Thread.sleep(50);
    }
    if (!isImageLoaded) {
        throw new RuntimeException("Image is not loaded!");
    }
    if (!isRVObserverCalled) {
        throw new RuntimeException("Resolution Variant observer is not called!");
    }
}
Also used : SunToolkit(sun.awt.SunToolkit) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) MultiResolutionToolkitImage(sun.awt.image.MultiResolutionToolkitImage) File(java.io.File)

Example 7 with java.awt.image

use of java.awt.image in project jdk8u_jdk by JetBrains.

the class MultiResolutionImageTest method testToolkitMultiResolutionImage.

static void testToolkitMultiResolutionImage() throws Exception {
    generateImages();
    File imageFile = new File(IMAGE_NAME_1X);
    String fileName = imageFile.getAbsolutePath();
    URL url = imageFile.toURI().toURL();
    testToolkitMultiResolutionImageChache(fileName, url);
    Image image = Toolkit.getDefaultToolkit().getImage(fileName);
    testToolkitImageObserver(image);
    testToolkitMultiResolutionImage(image, false);
    testToolkitMultiResolutionImage(image, true);
    image = Toolkit.getDefaultToolkit().getImage(url);
    testToolkitImageObserver(image);
    testToolkitMultiResolutionImage(image, false);
    testToolkitMultiResolutionImage(image, true);
}
Also used : MultiResolutionImage(java.awt.image.MultiResolutionImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) File(java.io.File) URL(java.net.URL)

Example 8 with java.awt.image

use of java.awt.image in project jdk8u_jdk by JetBrains.

the class MultiResolutionImageTest method testToolkitMultiResolutionImageLoad.

static void testToolkitMultiResolutionImageLoad() throws Exception {
    generateImages();
    File imageFile = new File(IMAGE_NAME_1X);
    String fileName = imageFile.getAbsolutePath();
    Image image = Toolkit.getDefaultToolkit().getImage(fileName);
    testToolkitMultiResolutionImageLoad(image);
}
Also used : MultiResolutionImage(java.awt.image.MultiResolutionImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) File(java.io.File)

Example 9 with java.awt.image

use of java.awt.image in project jdk8u_jdk by JetBrains.

the class MultiResolutionCachedImageTest method main.

public static void main(String[] args) {
    Image image = new TestMultiResolutionCachedImage(100);
    image.getWidth(null);
    image.getHeight(null);
    image.getProperty("comment", null);
    int scaledSize = 50;
    Image scaledImage = image.getScaledInstance(scaledSize, scaledSize, Image.SCALE_SMOOTH);
    if (!(scaledImage instanceof BufferedImage)) {
        throw new RuntimeException("Wrong scaled image!");
    }
    BufferedImage buffScaledImage = (BufferedImage) scaledImage;
    if (buffScaledImage.getWidth() != scaledSize || buffScaledImage.getHeight() != scaledSize) {
        throw new RuntimeException("Wrong scaled image!");
    }
    if (buffScaledImage.getRGB(scaledSize / 2, scaledSize / 2) != TEST_COLOR.getRGB()) {
        throw new RuntimeException("Wrong scaled image!");
    }
}
Also used : MultiResolutionCachedImage(sun.awt.image.MultiResolutionCachedImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage)

Example 10 with java.awt.image

use of java.awt.image in project jdk8u_jdk by JetBrains.

the class MultiResolutionImageObserverTest method main.

public static void main(String[] args) throws Exception {
    generateImages();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image image = Toolkit.getDefaultToolkit().getImage(IMAGE_NAME_1X);
    LoadImageObserver sizeObserver = new LoadImageObserver(WIDTH | HEIGHT);
    toolkit.prepareImage(image, -1, -1, sizeObserver);
    waitForImageLoading(sizeObserver, "The first observer is not called");
    LoadImageObserver bitsObserver = new LoadImageObserver(SOMEBITS | FRAMEBITS | ALLBITS);
    BufferedImage buffImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = (Graphics2D) buffImage.createGraphics();
    g2d.scale(2, 2);
    g2d.drawImage(image, 0, 0, bitsObserver);
    waitForImageLoading(bitsObserver, "The second observer is not called!");
    g2d.dispose();
}
Also used : Toolkit(java.awt.Toolkit) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

Image (java.awt.Image)518 BufferedImage (java.awt.image.BufferedImage)265 ImageIcon (javax.swing.ImageIcon)127 Graphics2D (java.awt.Graphics2D)97 IOException (java.io.IOException)76 File (java.io.File)65 Point (java.awt.Point)53 URL (java.net.URL)51 Graphics (java.awt.Graphics)46 JLabel (javax.swing.JLabel)31 Dimension (java.awt.Dimension)28 Rectangle (java.awt.Rectangle)27 AffineTransform (java.awt.geom.AffineTransform)25 Color (java.awt.Color)24 Test (org.junit.Test)24 RenderedImage (java.awt.image.RenderedImage)21 ArrayList (java.util.ArrayList)21 Toolkit (java.awt.Toolkit)20 IIOImage (javax.imageio.IIOImage)18 MediaTracker (java.awt.MediaTracker)17