* @param degrees
* @return rotated image
*/
public static BufferedImage rotateImage(Image inputImage, int degrees) {
BufferedImage retVal = null;
RenderedImage ri = JAI.create("awtImage", inputImage);
ParameterBlock pb = new ParameterBlock();
pb.addSource(ri);
TransposeType rotOp = null;
RenderedOp op = null;
if (degrees == 90) {
rotOp = TransposeDescriptor.ROTATE_90;
} else if (degrees == 180) {
rotOp = TransposeDescriptor.ROTATE_180;
} else if (degrees == 270) {
rotOp = TransposeDescriptor.ROTATE_270;
}
if (rotOp != null) {
// use Transpose operation
pb.add(rotOp);
op = JAI.create("transpose", pb);
} else {
// setup "normal" rotation
pb.add(ri.getWidth() / 2.0f);
pb.add(ri.getHeight() / 2.0f);
pb.add((float) Math.toRadians(degrees));
pb.add(new InterpolationNearest());
op = JAI.create("Rotate", pb, null);
}
PlanarImage myPlanar = op.createInstance();