Scaling, Shearing, Translating, and Rotating a Drawn Image - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Paint

Description

Scaling, Shearing, Translating, and Rotating a Drawn Image

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform tx = new AffineTransform();

    double scalex = .5;
    double scaley = 1;
    tx.scale(scalex, scaley);

    double shiftx = .1;
    double shifty = .3;
    tx.shear(shiftx, shifty);

    double x = 50;
    double y = 50;
    tx.translate(x, y);

    double radians = -Math.PI/4;
    tx.rotate(radians);

    g2d.drawImage(image, tx, this);
}

Related Tutorials