rotate Image 90 - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Rotate

Description

rotate Image 90

Demo Code

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

import java.awt.image.BufferedImage;

public class Main {
    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;
    }
}

Related Tutorials