Here you can find the source of transform(BufferedImage image, int numquadrants)
public static BufferedImage transform(BufferedImage image, int numquadrants)
//package com.java2s; //License from project: Apache License import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; public class Main { public static BufferedImage transform(BufferedImage image, int numquadrants) { int w0 = image.getWidth(); int h0 = image.getHeight(); int w1 = w0; int h1 = h0; int centerX = w0 / 2; int centerY = h0 / 2; if (numquadrants % 2 == 1) { w1 = h0;//from w w w . j av a 2 s. co m h1 = w0; } if (numquadrants % 4 == 1) { if (w0 > h0) { centerX = h0 / 2; centerY = h0 / 2; } else if (h0 > w0) { centerX = w0 / 2; centerY = w0 / 2; } // if h0 == w0, then use default } else if (numquadrants % 4 == 3) { if (w0 > h0) { centerX = w0 / 2; centerY = w0 / 2; } else if (h0 > w0) { centerX = h0 / 2; centerY = h0 / 2; } // if h0 == w0, then use default } AffineTransform affineTransform = new AffineTransform(); affineTransform.setToQuadrantRotation(numquadrants, centerX, centerY); AffineTransformOp opRotated = new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_BILINEAR); BufferedImage transformedImage = new BufferedImage(w1, h1, image.getType()); transformedImage = opRotated.filter(image, transformedImage); return transformedImage; } }