Java BufferedImage Rotate rotate(BufferedImage image, double theta, int anchorX, int anchorY)

Here you can find the source of rotate(BufferedImage image, double theta, int anchorX, int anchorY)

Description

rotate

License

Open Source License

Declaration

private static BufferedImage rotate(BufferedImage image, double theta, int anchorX, int anchorY) 

Method Source Code

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

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;

import java.awt.geom.AffineTransform;

import java.awt.image.BufferedImage;

public class Main {
    private static BufferedImage rotate(BufferedImage image, double theta, int anchorX, int anchorY) {
        return createTransformed(image, AffineTransform.getRotateInstance(theta, anchorX, anchorY));
    }/*from w w  w  .  j a  va2 s . co m*/

    private static BufferedImage createTransformed(BufferedImage image, AffineTransform at) {
        BufferedImage newImage = createImage(image);
        Graphics2D g = newImage.createGraphics();

        g.transform(at);
        g.drawImage(image, 0, 0, null);
        g.dispose();

        return newImage;
    }

    public static BufferedImage createImage(Rectangle bounds) {
        return createImage(bounds, BufferedImage.TYPE_INT_ARGB);
    }

    public static BufferedImage createImage(Rectangle bounds, int type) {
        return createImage(bounds.width, bounds.height, type);
    }

    public static BufferedImage createImage(Image image) {
        return createImage(image, BufferedImage.TYPE_INT_ARGB);
    }

    public static BufferedImage createImage(Image image, int type) {
        return createImage(image.getWidth(null), image.getHeight(null), type);
    }

    public static BufferedImage createImage(int width, int height) {
        return createImage(width, height, BufferedImage.TYPE_INT_ARGB);
    }

    public static BufferedImage createImage(int width, int height, int type) {
        return new BufferedImage(width, height, type);
    }

    private static BufferedImage transform(BufferedImage image, int sx, int sy, int dx, int dy) {
        AffineTransform at = new AffineTransform();

        at.concatenate(AffineTransform.getScaleInstance(sx, sy));
        at.concatenate(AffineTransform.getTranslateInstance(dx, dy));

        return createTransformed(image, at);
    }
}

Related

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