What I'm trying to do:
I am looking to transform an image by rotating it by either 90, 180, or 270 degrees.
What's happening:
For some reason when I am rotating a 640x360 pixel image, 90 degrees, I end up getting a 500x500 image, instead of a 360x640 image, so the image gets re-sized for some reason...
I also tried a 5000 x 2000 or so image, and I got a 4800x4800 image as a result when rotated.
180 works correctly and produces the same size as no rotation, but 90 and 270 don't work...
What I've noticed
I noticed that degrees isn't the exactly the same as the Radian value, so I'm trying to use Radians instead.
I've noticed that using Math.toRadians(90)
results in a clockwise rotation, and not a couterclockwise rotation... I'm curious why the positive rotation is clockwise, and not counterclockwise?
Code:
public static BufferedImage rotateImage(BufferedImage image) throws IOException
{
AffineTransform transform = new AffineTransform();
transform.rotate(Math.PI/2, image.getWidth()/2, image.getHeight()/2);
AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
image = op.filter(image, null);
ImageIO.write(image,"PNG",new File("C:\\a.png"));
return image;
}
Any advice is appreciated, thank you for your time!