Store Image to File


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public String store(Image image, String fileType) throws IOException {
  2. File imageDir = createDir(IMAGE_DIR);
  3. String imageFileName = generateFilenameFromTimestamp(null, new Date(),
  4. fileType);
  5. BufferedImage bufferedImage = new BufferedImage(image.getWidth(null),
  6. image.getHeight(null), BufferedImage.TYPE_INT_RGB);
  7. Graphics2D g2 = bufferedImage.createGraphics();
  8. g2.drawImage(image, null, null);
  9. File imageFile = new File(imageDir, imageFileName);
  10. ImageIO.write(bufferedImage, fileType, imageFile);
  11.  
  12. return imageFile.getPath();
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.