Here you can find the source of rotateFortyFiveClockwise(BufferedImage img)
Parameter | Description |
---|---|
img | The BufferedImage to rotate. |
public static BufferedImage rotateFortyFiveClockwise(BufferedImage img)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; public class Main { /**// w ww . ja v a 2s . c om * Rotate img 45 degrees clockwise. * * @param img The BufferedImage to rotate. * @return The given image rotate 45 degrees clockwise. */ public static BufferedImage rotateFortyFiveClockwise(BufferedImage img) { double piOverFour = Math.PI / 4.0; // the diagonal of the square becomes the new dimensions int w = img.getWidth(); int h = img.getHeight(); int diag = (int) Math.sqrt(w * w + h * h) + 2; // padding for good measure BufferedImage rotated = new BufferedImage(diag, diag, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = (Graphics2D) rotated.getGraphics(); AffineTransform trans = g2d.getTransform(); // the image is rotate about the top-left corner // so move it to the top center and rotate trans.translate(diag / 2, 0); trans.rotate(piOverFour); g2d.drawImage(img, trans, null); return rotated; } }