Advertisement
kuchuz

PBO-C 7 : ImageFileManager

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