Here you can find the source of rotate90(BufferedImage bi)
Parameter | Description |
---|---|
bi | A given image to rotate. |
public static BufferedImage rotate90(BufferedImage bi)
//package com.java2s; /*//from w w w . j a va 2 s.c o m This file is part of JFLICKS. JFLICKS 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 3 of the License, or (at your option) any later version. JFLICKS 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. You should have received a copy of the GNU General Public License along with JFLICKS. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.Graphics2D; import java.awt.image.BufferedImage; public class Main { /** * Rotate a BufferedImage 90 degrees clockwise. * * @param bi A given image to rotate. * @return A new image that is rotated 90 degrees clockwise. */ public static BufferedImage rotate90(BufferedImage bi) { BufferedImage result = null; if (bi != null) { int w = bi.getWidth(); int h = bi.getHeight(); int endw = h; int endh = w; int max = w; if (h > w) { max = h; endw = w; endh = h; } result = new BufferedImage(max, max, BufferedImage.TYPE_INT_ARGB); Graphics2D bg = result.createGraphics(); double dmax = ((double) max) / 2.0; bg.rotate(Math.toRadians(90), dmax, dmax); bg.drawImage(bi, 0, 0, w, h, 0, 0, w, h, null); bg.dispose(); if (endw == h) { result = result.getSubimage(max - endw, 0, endw, endh); } else { result = result.getSubimage(0, 0, endh, endw); } } return (result); } }