Posted By

roock on 11/18/08


Tagged

image file


Versions (?)

Store Image to File


 / Published in: Java
 

  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  

You need to login to post a comment.