Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. public File writeImage(BufferedImage img, String name) {
  2. if (img == null || name == null || name.isEmpty()) return null;
  3. if (!outputFolder.exists()) outputFolder.mkdirs();
  4.  
  5. File file = new File(outputFolder, String.format("%s.png", name));
  6. int i = 1;
  7. while (file.exists()) {
  8. file = new File(outputFolder, String.format("%s_%s.png", name, String.valueOf(i)));
  9. i++;
  10. }
  11.  
  12. try {
  13. ImageIO.write(img, "png", file);
  14. return file;
  15. } catch (Exception ex) {
  16. ex.printStackTrace();
  17. return null;
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement