Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to rotate image in java?

    • 0
    • 4
    • 8
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.40k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: