Here I have illustrated how to rotate image using java code.
Impot imgscalr-lib-4.2.jar for Scalr class to rotated image on various angles.
Below code will rotated image on 90 degree angle.
File file= new File("file-path");
BufferedImage src = ImageIO.read(file);
System.out.println(src.getWidth() + "x" + src.getHeight());
BufferedImage rotated = Scalr.rotate(src, Scalr.Rotation.CW_90, Scalr.OP_ANTIALIAS);
BufferedImage scaled = Scalr.resize(rotated, Scalr.Method.SPEED, Scalr.Mode.FIT_TO_HEIGHT, 1336, 768, Scalr.OP_ANTIALIAS);
System.out.println(scaled.getWidth() + "x" + scaled.getHeight());
ImageIO.write(scaled,"png" , "/rotated.png");
Thank you.
0 Comment(s)