Java BufferedImage Rotate rotate(BufferedImage image, int degrees)

Here you can find the source of rotate(BufferedImage image, int degrees)

Description

Method used to rotate an image based on an inputted degree value

License

Open Source License

Parameter

Parameter Description
image The image file to rotate
degrees The amount of rotation in degrees

Return

The rotated image file

Declaration

public static BufferedImage rotate(BufferedImage image, int degrees) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.*;
import java.awt.image.BufferedImage;

public class Main {
    /**/*ww  w.  j  av a 2  s. c  o m*/
     * Method used to rotate an image based on an inputted degree value
     * @param image The image file to rotate
     * @param degrees The amount of rotation in degrees
     * @return The rotated image file
     */
    public static BufferedImage rotate(BufferedImage image, int degrees) {
        BufferedImage blankCanvas = new BufferedImage(image.getWidth(), image.getHeight(),
                BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2D = (Graphics2D) blankCanvas.getGraphics();
        g2D.rotate(Math.toRadians(degrees), image.getWidth() / 2, image.getHeight() / 2);
        g2D.drawImage(image, 0, 0, null);

        return image = blankCanvas;
    }
}

Related

  1. rotate(BufferedImage bi, double rotateValue)
  2. rotate(BufferedImage bi, int degree)
  3. rotate(BufferedImage image, double theta)
  4. rotate(BufferedImage image, double theta, int anchorX, int anchorY)
  5. rotate(BufferedImage image, float theRadiansAngle)
  6. rotate(BufferedImage img, int angle)
  7. rotate(BufferedImage img, int angle)
  8. rotate(BufferedImage img, int angle)
  9. rotate(BufferedImage img, int angle)