rotate Image 270 - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Rotate

Description

rotate Image 270

Demo Code

/*//from   www.j a v a 2 s .c o m
 * Copyright 2000-2013 Enonic AS
 * http://www.enonic.com/license
 */
//package com.java2s;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage rotateImage270(BufferedImage image,
            final int bufferedImageType) {
        return rotateImage90(rotateImage180(image, bufferedImageType),
                bufferedImageType);
    }

    public static BufferedImage rotateImage90(BufferedImage image,
            final int bufferedImageType) {
        int width = image.getWidth();
        int height = image.getHeight();
        BufferedImage destImage = new BufferedImage(height, width,
                bufferedImageType);

        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                destImage.setRGB(height - 1 - j, i, image.getRGB(i, j));
            }
        }

        return destImage;
    }

    public static BufferedImage rotateImage180(BufferedImage image,
            final int bufferedImageType) {
        return rotateImage90(rotateImage90(image, bufferedImageType),
                bufferedImageType);
    }
}

Related Tutorials