0

I have some code which generates images and saves them. It does this with a BufferedImage and the images can range from 1x1 all the way to 8000x8000.

I save my BufferedImage using the following code:

ImageIO.write(image, "png", outputfile);

When I am generating the image it calculates a percentage to show the user.

How do I get the percentage a BufferedImage is saved? Also how do I use this percentage to and it to the overall percentage for something else?

This question provides an answer to what I want, but I have a hard time understanding it and when I use the code given. I can not get it to work.

Community
  • 1
  • 1
Forseth11
  • 1,418
  • 1
  • 12
  • 21
  • It's a little complex, but the basic idea is, use `ImageIO.createImageOutputStream` passing it the destination of the image (ie a `File`, `RandomAccessFile` or `OutputStream`), use `ImageIO.getImageWritersByFormatName("...");` to get an `Iterator` of the available writers for the output format (`"png"`), get a `ImageWriter` from this `Iterator` and then use `addIIOWriteProgressListener` to add a `IIOWriteProgressListener` to it and then use `ImageWriter#setOutput` and pass the `ImageOutputStream` which you created first to it...easy :P – MadProgrammer May 27 '15 at 05:54
  • @MadProgrammer I have to go now, but should I delete this post because it is a duplicate? – Forseth11 May 27 '15 at 05:58
  • Probably not a bad idea ;) – MadProgrammer May 27 '15 at 06:01

0 Answers0