Java examples for 2D Graphics:Transform
This returns an affine transform which will keep the center point in the center and scale the x- and y-directions uniformly by the factor given.
//package com.java2s; import java.awt.geom.AffineTransform; public class Main { /**/*w w w . j a v a2s .c o m*/ * This returns an affine transform which will keep the center point in * the center and scale the x- and y-directions uniformly by the factor * given. Note that a value of 1 corresponds to the identify transform, * values less than 1 will "zoom out," and values greater than 1 will * "zoom in." (NOTE: that this transform should be pre-concatenated with * the existing one!) */ public static AffineTransform getZoomTransform(double zoomFactor, int width, int height) { double tx = width / 2. * (1. - zoomFactor); double ty = height / 2. * (1 - zoomFactor); return new AffineTransform(zoomFactor, 0., 0., zoomFactor, tx, ty); } }