Here you can find the source of rotateImage(Image originalImage, double theta)
Parameter | Description |
---|---|
originalImage | a parameter |
theta | angle in radians (a positive angle indicates clockwise rotation) |
public static Image rotateImage(Image originalImage, double theta)
//package com.java2s; import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingHints; import java.awt.image.BufferedImage; public class Main { /** Rendering hints - render at highest quality*/ private static final RenderingHints RENDERING_HINTS_HIGH_QUALITY = new RenderingHints(null); /**/*from w ww . j a v a2 s . c o m*/ * Rotates the image around its center by the specified angle. The original image * size is maintained, so cropping may occur as a result of the rotation. * * @param originalImage * @param theta angle in radians (a positive angle indicates clockwise rotation) * @return rotated image */ public static Image rotateImage(Image originalImage, double theta) { BufferedImage newImage = new BufferedImage(originalImage.getWidth(null), originalImage.getHeight(null), BufferedImage.TYPE_INT_ARGB_PRE); Graphics2D g2d = newImage.createGraphics(); g2d.setRenderingHints(RENDERING_HINTS_HIGH_QUALITY); g2d.rotate(theta, originalImage.getWidth(null) / (double) 2, originalImage.getHeight(null) / (double) 2); g2d.drawImage(originalImage, 0, 0, null); g2d.dispose(); return newImage; } }