Search in sources :

Example 56 with java.awt.image

use of java.awt.image in project JMRI by JMRI.

the class LcdClockFrame method scaleImage.

// Added method to scale the clock digit images to fit the
// size of the display window
public void scaleImage() {
    int iconHeight;
    int iconWidth;
    int frameHeight = this.getContentPane().getSize().height;
    int frameWidth = this.getContentPane().getSize().width;
    if ((double) frameWidth / (double) frameHeight > aspect) {
        iconHeight = frameHeight;
        iconWidth = (int) (iconAspect * iconHeight);
    } else {
        //this DOES NOT allow space for the Run/Stop button, if it is
        //enabled.  When the Run/Stop button is enabled, the layout will have to be changed
        iconWidth = (int) (frameWidth / 4.5);
        iconHeight = (int) (iconWidth / iconAspect);
    }
    for (int i = 0; i < 10; i++) {
        Image scaledImage = baseTubes[i].getImage().getScaledInstance(iconWidth, iconHeight, Image.SCALE_SMOOTH);
        tubes[i].setImage(scaledImage);
    }
    Image scaledImage = baseColon.getImage().getScaledInstance(iconWidth / 2, iconHeight, Image.SCALE_SMOOTH);
    colonIcon.setImage(scaledImage);
    //      Ugly hack to force frame to redo the layout.
    //      Without this the image is scaled but the label size and position doesn't change.
    //      doLayout() doesn't work either
    this.setVisible(false);
    this.remove(b);
    if (clock.getShowStopButton()) {
        // pick up clock prefs choice
        this.getContentPane().add(b);
    }
    this.setVisible(true);
    return;
}
Also used : Image(java.awt.Image)

Example 57 with java.awt.image

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

the class MultiResolutionDisabledImageTest method main.

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);
    }
}
Also used : BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) MultiResolutionImage(java.awt.image.MultiResolutionImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) MultiResolutionImage(java.awt.image.MultiResolutionImage) BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage)

Example 58 with java.awt.image

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

the class ClassCastExceptionForInvalidSurface method main.

public static void main(final String[] args) throws InterruptedException {
    // Catch all uncaught exceptions and treat them as test failure
    Thread.setDefaultUncaughtExceptionHandler((t, e) -> failed = e);
    // Data for rendering
    BufferedImage bi = new BufferedImage(10, 10, TYPE_INT_ARGB);
    FontRenderContext frc = new FontRenderContext(null, false, false);
    Font font = new Font("Serif", Font.PLAIN, 12);
    GlyphVector gv = font.createGlyphVector(frc, new char[] { 'a', '1' });
    Thread t1 = new Thread(() -> {
        while (!isComplete()) {
            vi = gc.createCompatibleVolatileImage(10, 10);
            if (!list.offer(vi)) {
                vi.flush();
            }
        }
        list.forEach(Image::flush);
    });
    Thread t2 = new Thread(() -> {
        while (!isComplete()) {
            VolatileImage vi = list.poll();
            if (vi != null) {
                vi.flush();
            }
        }
    });
    Thread t3 = new Thread(() -> {
        while (!isComplete()) {
            vi.createGraphics().drawImage(bi, 1, 1, null);
        }
    });
    Thread t4 = new Thread(() -> {
        while (!isComplete()) {
            vi.createGraphics().drawGlyphVector(gv, 0, 0);
            vi.createGraphics().drawOval(0, 0, 10, 10);
            vi.createGraphics().drawLine(0, 0, 10, 10);
            vi.createGraphics().drawString("123", 1, 1);
            vi.createGraphics().draw(new Rectangle(0, 0, 10, 10));
            vi.createGraphics().fillOval(0, 0, 10, 10);
            final Graphics2D graphics = vi.createGraphics();
            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            graphics.fillPolygon(new int[] { 0, 10, 10, 0 }, new int[] { 0, 0, 10, 10 }, 4);
        }
    });
    t1.start();
    t2.start();
    t3.start();
    t4.start();
    t1.join();
    t2.join();
    t3.join();
    t4.join();
    if (failed != null) {
        System.err.println("Test failed");
        failed.printStackTrace();
    }
}
Also used : GlyphVector(java.awt.font.GlyphVector) VolatileImage(java.awt.image.VolatileImage) Rectangle(java.awt.Rectangle) FontRenderContext(java.awt.font.FontRenderContext) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) VolatileImage(java.awt.image.VolatileImage) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Example 59 with java.awt.image

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

the class NonOpaqueDestLCDAATest method render.

public void render(Graphics g, int w, int h) {
    initImages(w, h);
    g.setColor(new Color(0xAD, 0xD8, 0xE6));
    g.fillRect(0, 0, w, h);
    Graphics2D g2d = (Graphics2D) g.create();
    for (Image im : images) {
        g2d.drawImage(im, 0, 0, null);
        g2d.translate(0, im.getHeight(null));
    }
}
Also used : Color(java.awt.Color) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) VolatileImage(java.awt.image.VolatileImage) Graphics2D(java.awt.Graphics2D)

Example 60 with java.awt.image

use of java.awt.image in project processdash by dtuma.

the class ImageResizingGraphics method drawImage.

public boolean drawImage(Image image, int x, int y, ImageObserver observer) {
    AffineTransform transform = getTransform();
    if (transform == null || ((transform.getType() & AffineTransform.TYPE_MASK_SCALE) == 0))
        return delegate.drawImage(image, x, y, observer);
    else {
        double scaleX = transform.getScaleX();
        double scaleY = transform.getScaleY();
        AffineTransform newTransform = new AffineTransform(transform);
        newTransform.scale(1 / scaleX, 1 / scaleY);
        setTransform(newTransform);
        int width = image.getWidth(observer);
        int height = image.getHeight(observer);
        // workaround for Java bug 4937376
        Image img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        img.getGraphics().drawImage(image, 0, 0, null);
        img = img.getScaledInstance((int) Math.round(width * scaleX), (int) Math.round(height * scaleY), Image.SCALE_SMOOTH);
        boolean result = delegate.drawImage(img, x, y, null);
        setTransform(transform);
        return result;
    }
}
Also used : AffineTransform(java.awt.geom.AffineTransform) RenderableImage(java.awt.image.renderable.RenderableImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) RenderedImage(java.awt.image.RenderedImage) Paint(java.awt.Paint) BufferedImage(java.awt.image.BufferedImage)

Aggregations

Image (java.awt.Image)515 BufferedImage (java.awt.image.BufferedImage)263 ImageIcon (javax.swing.ImageIcon)127 Graphics2D (java.awt.Graphics2D)97 IOException (java.io.IOException)73 File (java.io.File)64 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