trizehn

ImageFileManager

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