This returns an affine transform which will rotate the contents of the window by -90 degrees. - Java 2D Graphics

Java examples for 2D Graphics:Transform

Description

This returns an affine transform which will rotate the contents of the window by -90 degrees.

Demo Code


//package com.java2s;

import java.awt.geom.AffineTransform;

public class Main {
    public static void main(String[] argv) throws Exception {
        int width = 2;
        int height = 2;
        System.out.println(getCWRotateTransform(width, height));
    }//from ww w  .  j  a va  2 s  . c o m

    /**
     * This returns an affine transform which will rotate the contents
     * of the window by -90 degrees.  (NOTE: that this transform should
     * be pre-concatenated with the existing one!) The returned
     * transform will rotate the contents of the window by -90 degrees
     * while keeping the centerpoint the same.  The x and y-scaling
     * will be adjusted to keep the same area visible. */
    public static AffineTransform getCWRotateTransform(int width, int height) {

        return new AffineTransform(0., ((double) height) / width,
                -((double) width) / height, 0., (double) width, 0.);
    }
}

Related Tutorials