Java BufferedImage Rotate rotateImage(BufferedImage imageToRotate, float degrees)

Here you can find the source of rotateImage(BufferedImage imageToRotate, float degrees)

Description

Rotates 90, -90 deegrees

License

Open Source License

Parameter

Parameter Description
imageToRotate a parameter
degrees 90 or -90 rotation.

Declaration

public static BufferedImage rotateImage(BufferedImage imageToRotate, float degrees) 

Method Source Code

//package com.java2s;
/*//w  ww .  ja va 2 s. c om
 * ====================================================================
 *
 * License:        GNU General Public License
 *
 * Note: Original work copyright to respective authors
 *
 * This file is part of Blended (c) 2009-2010 University of Valladolid..
 *
 * Blended is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Blended is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *
 * Module developed at the University of Valladolid http://www.eduvalab.uva.es
 *
 * http://www.itnt.uva.es , http://www.eduvalab.uva.es
 *
 * Designed and directed by Juan Pablo de Castro with 
 * the effort of many other students of telecommunication 
 * engineering.
 * This module is provides as-is without any 
 * guarantee. Use it as your own risk.
 *
 * @author Juan Pablo de Castro
 * @author Jesus Rodilana
 * @author Mar?a Jes?s Verd? 
 * @author Luisa Regueras 
 * @author Elena Verd?
 * 
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package blended
 ***********************************************************************/

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    /**
     * Rotates 90, -90 deegrees
     * @param imageToRotate
     * @param degrees 90 or -90 rotation.
     * @return
     */
    public static BufferedImage rotateImage(BufferedImage imageToRotate, float degrees) {
        if (degrees != 90.0 && degrees != -90.0)
            throw new IllegalArgumentException("Only implemented +90 and -90 rotation");

        BufferedImage rotatedImage = new BufferedImage(imageToRotate.getHeight(null), imageToRotate.getWidth(null),
                imageToRotate.getType());

        Graphics2D g2d = (Graphics2D) rotatedImage.getGraphics();
        g2d.rotate(Math.toRadians(degrees));
        g2d.drawImage(imageToRotate, 0, -rotatedImage.getWidth(null), null);

        return rotatedImage;
    }
}

Related

  1. rotateImage(BufferedImage image, double angle)
  2. rotateImage(BufferedImage image, double angle)
  3. rotateImage(BufferedImage image, double radians)
  4. rotateImage(BufferedImage image, float angle)
  5. rotateImage(BufferedImage image, int cwRotationNeeded)
  6. rotateImage(BufferedImage img, double angle)
  7. rotateImage(BufferedImage img, double angle, int type)
  8. rotateImage(BufferedImage img, double degree)
  9. rotateImage(BufferedImage src, double degrees)