Java BufferedImage Rotate rotate(BufferedImage source, int angle)

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

Description

Rotates a given image to a given angle.

License

Apache License

Parameter

Parameter Description
source The source image.
angle The angle to rotate by (in degrees).

Return

BufferedImage

Declaration

public static BufferedImage rotate(BufferedImage source, int angle) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    private static BufferedImage bimg;
    private static Graphics2D g2;
    private static int w;
    private static int h;

    /**/*from w ww .  j a  va  2 s  .  c  om*/
     * Rotates a given image to a given angle.
     * @param source The source image.
     * @param angle The angle to rotate by (in degrees).
     * @return BufferedImage
     */
    public static BufferedImage rotate(BufferedImage source, int angle) {
        w = source.getWidth();
        h = source.getHeight();
        bimg = new BufferedImage(w, h, source.getType());
        g2 = bimg.createGraphics();
        g2.rotate(Math.toRadians(angle), w / 2, h / 2);
        g2.drawImage(source, null, 0, 0);

        return bimg;
    }
}

Related

  1. rotate(BufferedImage img, int angle)
  2. rotate(BufferedImage img, int angle)
  3. rotate(BufferedImage img, int angle)
  4. rotate(BufferedImage img, int angle)
  5. rotate(BufferedImage img, int b, int a, int angle)
  6. rotate(BufferedImage src)
  7. rotate(final BufferedImage image, final int angle)
  8. rotate(Graphics2D g, BufferedImage newImg, int x, int y, int width, int height, int angle, int originX, int originY)
  9. rotate90(BufferedImage bi)