Advertisement
iccaka

Java Image rotation program

Oct 27th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. import org.imgscalr.Scalr;
  2.  
  3. import javax.imageio.ImageIO;
  4. import java.awt.image.BufferedImage;
  5. import java.io.File;
  6. import java.io.IOException;
  7. import java.util.Scanner;
  8.  
  9. public class Main {
  10.  
  11.     private static String DEFAULT_IMAGE_PATH = "images/java.jpg";
  12.     private static String DEFAULT_IMAGE_TYPE = "jpg";
  13.  
  14.     public static void main(String[] args) throws IOException {
  15.  
  16.         BufferedImage bi = null;
  17.         BufferedImage manipulatedBi = null;
  18.  
  19.         try {
  20.             bi = ImageIO.read(new File(DEFAULT_IMAGE_PATH));
  21.         } catch (IOException e) {
  22.             System.out.println(e.toString());
  23.         }
  24.  
  25.         boolean rotateCommandIsProper = false;
  26.  
  27.         Scanner sc = new Scanner(System.in);
  28.         String rotateCommand = sc.nextLine();
  29.  
  30.         while (!rotateCommandIsProper) {
  31.             switch (rotateCommand) {
  32.                 case "90":
  33.                     rotateCommandIsProper = true;
  34.                     manipulatedBi = org.imgscalr.Scalr.rotate(bi, Scalr.Rotation.CW_90);
  35.                     break;
  36.                 case "180":
  37.                     rotateCommandIsProper = true;
  38.                     manipulatedBi = org.imgscalr.Scalr.rotate(bi, Scalr.Rotation.CW_180);
  39.                     break;
  40.                 case "270":
  41.                     rotateCommandIsProper = true;
  42.                     manipulatedBi = org.imgscalr.Scalr.rotate(bi, Scalr.Rotation.CW_270);
  43.                     break;
  44.                 default:
  45.                     rotateCommandIsProper = false;
  46.                     System.out.println("Command not understood");
  47.                     rotateCommand = sc.nextLine();
  48.             }
  49.         }
  50.  
  51.         if(manipulatedBi != null){
  52.             ImageIO.write(manipulatedBi, DEFAULT_IMAGE_TYPE, new File(DEFAULT_IMAGE_PATH));
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement