Advertisement
lamaulfarid

ImageFileManager

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