Dwinanda

Image Viewer (ImageFileManager)

Dec 7th, 2020
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1.  
  2. /**
  3.  * merupakan class yang berisikan untuk Load image dan save image untuk diproses lebih lanjut
  4.  *
  5.  * @author Dwinanda Bagoes Ansori
  6.  * @version Final Version, 8 Desember 2020
  7.  */
  8. import java.io.*;
  9. import java.awt.image.*;
  10. import javax.imageio.*;
  11.  
  12. public class ImageFileManager
  13. {
  14.     private static final String IMAGE_FORMAT = "jpg";
  15.    
  16.     public ImageFileManager()
  17.     {
  18.        
  19.     }
  20.  
  21.     public static OFImage loadImage(File imageFile)
  22.     {
  23.         try
  24.         {
  25.             BufferedImage image = ImageIO.read(imageFile);
  26.             if (image == null || (image.getWidth(null) < 0))
  27.             {
  28.                 return null;
  29.             }
  30.             return new OFImage(image);
  31.         }
  32.         catch (IOException exc)
  33.         {
  34.             return null;
  35.         }
  36.     }
  37.    
  38.     public static void saveImage(OFImage image, File file)
  39.     {
  40.         try
  41.         {
  42.             ImageIO.write(image, IMAGE_FORMAT, file);
  43.         }
  44.         catch (IOException exc)
  45.         {
  46.             return;
  47.         }
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment