Here you can find the source of rotateImage(BufferedImage image, double radians)
public static BufferedImage rotateImage(BufferedImage image, double radians)
//package com.java2s; //License from project: Open Source License import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; public class Main { public static BufferedImage rotateImage(BufferedImage image, double radians) { BufferedImage rotatedImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY); Graphics2D g2d = rotatedImage.createGraphics(); g2d.rotate(radians);/* ww w .java 2 s . c om*/ g2d.setBackground(Color.WHITE); int maxOfWidthHieght = Math.max(image.getWidth(null), image.getHeight(null)); g2d.clearRect(-5 * maxOfWidthHieght, -5 * maxOfWidthHieght, 10 * maxOfWidthHieght, 10 * maxOfWidthHieght); g2d.drawImage(image, 0, 0, Color.WHITE, null); g2d.dispose(); return rotatedImage; } }