Here you can find the source of rotate(BufferedImage img, int angle)
public static BufferedImage rotate(BufferedImage img, int angle)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics2D; import java.awt.image.BufferedImage; public class Main { public static BufferedImage rotate(BufferedImage img, int angle) { double sin = Math.abs(Math.sin(Math.toRadians(angle))), cos = Math.abs(Math.cos(Math.toRadians(angle))); int w = img.getWidth(null), h = img.getHeight(null); int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin); BufferedImage bimg = new BufferedImage(neww, newh, img.getType()); Graphics2D g = bimg.createGraphics(); g.translate((neww - w) / 2, (newh - h) / 2); g.rotate(Math.toRadians(angle), w / 2, h / 2); g.drawRenderedImage(img, null);/* w w w.j a v a 2 s . co m*/ g.dispose(); return bimg; } }