We can assume that BufferedImage is the best option for image processing in Java. Although this is convenient, when reading huge images it often ends:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
Increasing the size of the virtual machine is not a solution, as some input files are really huge in my case.
So, I'm looking for a way (s) how an image can be read gradually, from a stream.
I suspect that ImageIO.createImageInputStream() from ImageIO might match the score, but I'm not sure how to use it to read fragments gradually. In addition, there are the PNGMetadata and PNGImageReader classes available on the JDK rt.jar that seem useful, but I have not found simple examples of their use.
Is this the way, or are there better alternatives?
java stream image png
blackSmith
source share