One may suggest that BufferedImage
is the best option to process an image in Java. While it's convenient, when reading huge images it often ends up in:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
Increasing VM size isn't a solution since some input files are really huge in my case.
So I'm looking for the way(s) how an image can be read progressively, from a stream.
I suspect that ImageIO.createImageInputStream()
from the ImageIO
might fit the bill, but I'm not sure how to use it to read the chunks progressively.
Also, there are the classes PNGMetadata
& PNGImageReader
available on the JDK's rt.jar
which seem to be useful, but I didn't find simple examples of their usage.
Is this the way to go, or there are better alternatives?