Java Image Rotate rotateImage(Image originalImage, double theta)

Here you can find the source of rotateImage(Image originalImage, double theta)

Description

Rotates the image around its center by the specified angle.

License

Open Source License

Parameter

Parameter Description
originalImage a parameter
theta angle in radians (a positive angle indicates clockwise rotation)

Return

rotated image

Declaration

public static Image rotateImage(Image originalImage, double theta) 

Method Source Code

//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;
    }
}

Related

  1. rotate(Image img, float radian)
  2. Rotate(Image src, int angel)
  3. rotateImage(final File imagePath, int numquadrants)
  4. rotateImage(final Image img, final Point location, final double degrees)
  5. rotateImage(Image inImage, int inMaxWidth, int inMaxHeight, int inRotationDegrees)
  6. rotateImage(String img_fn, int orient, String dest_fn)