Java BufferedImage Rotate rotate(BufferedImage img, int angle)

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

Description

rotate

License

Apache License

Declaration

public static BufferedImage rotate(BufferedImage img, 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 {
    public static BufferedImage rotate(BufferedImage img, int angle) {
        int w = img.getWidth();
        int h = img.getHeight();
        BufferedImage dimg = new BufferedImage(w, h, img.getType());
        Graphics2D g = dimg.createGraphics();
        g.rotate(Math.toRadians(angle), w / 2, h / 2);
        g.drawImage(img, null, 0, 0);//from w ww .  java2  s.c o m
        return dimg;
    }

    public static void drawImage(BufferedImage srcImg, BufferedImage img2Draw, int w, int h) {
        if (w == -1)
            w = (int) (srcImg.getWidth() / 2);
        if (h == -1)
            h = (int) (srcImg.getHeight() / 2);
        System.out.println("AWT Image Wt: " + w + " And Ht: " + h);
        Graphics2D g2 = srcImg.createGraphics();
        g2.drawImage(img2Draw, w, h, null);
        g2.dispose();
    }
}

Related

  1. rotate(BufferedImage image, double theta, int anchorX, int anchorY)
  2. rotate(BufferedImage image, float theRadiansAngle)
  3. rotate(BufferedImage image, int degrees)
  4. rotate(BufferedImage img, int angle)
  5. rotate(BufferedImage img, int angle)
  6. rotate(BufferedImage img, int angle)
  7. rotate(BufferedImage img, int b, int a, int angle)
  8. rotate(BufferedImage source, int angle)
  9. rotate(BufferedImage src)