draw Image - Java 2D Graphics

Java examples for 2D Graphics:Image

Description

draw Image

Demo Code


import java.awt.Component;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Polygon;
import java.awt.font.FontRenderContext;
import java.awt.font.LineBreakMeasurer;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.ImageObserver;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import javax.swing.plaf.basic.BasicGraphicsUtils;

public class Main{
    public static final double density = getDisplayDensity();
    public static final double scale = getScale();
    public static void drawImage(Graphics g, Image img, int x, int y,
            ImageObserver observer) {
        g.drawImage(img, scale(x), scale(y), scale(img.getWidth(observer)),
                scale(img.getHeight(observer)), observer);
    }/*w w w . java 2s. co m*/
    public static void drawImage(Graphics g, Image img, int x, int y,
            int w, int h, ImageObserver observer) {
        g.drawImage(img, scale(x), scale(y), scale(w), scale(h), observer);
    }
    public static void drawImage(Graphics g, Image img, int dx1, int dy1,
            int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
            ImageObserver observer) {
        g.drawImage(img, scale(dx1), scale(dy1), scale(dx2), scale(dy2),
                sx1, sy1, sx2, sy2, observer);
    }
    public static int scale(int i) {
        return (int) (i * density / scale);
    }
}

Related Tutorials