The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.awt  [78 examples] > Images  [4 examples]

e596. Scaling, Shearing, Translating, and Rotating a Drawn Image

See also e575 The Quintessential Drawing Program and e594 Reading an Image or Icon from a File.
    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 Examples
e594. Reading an Image or Icon from a File
e595. Drawing an Image
e597. Creating a Gray Version of an Icon

See also: Colors    Components    Containers    Cursors    Drawing    Events    Focus    Frames    GridBagLayout    Shapes    Simulating Events    Text    The Screen   


© 2002 Addison-Wesley.