I've been working on a piece of software which involves storing and retrieving large images in a database (the database aspect isn't relevant to the problem) and I keep running into memory issues related to the fact that I can't find a way to reuse buffers for storing image data (at least in javax.imagio). More specifically, I'm in a scenario where the images are viewed one at a time and never need to be simultaneously in memory. The imageio API allows to specify an existing BufferedImage as a target for a read operation, but this will only work if the underlying SampleModels/DataBuffers are identical. In my case, the images stored and loaded from the database are in a compressed format, and can vary greatly in format resulting in errors whenever I try to reuse a BufferedImage (number of bands/samples, interleaved vs non-interleaved...). It seems impossible to just allocate a single huge byte array and keep reading images into it, overwriting whatever was in it previously. An even better solution would be to be able to get uncompressed data as a stream but I can't find this anywhere either.
Does anyone know of a lib (or a way using Java SE only) that can read most image formats in one of these two ways:
-Read an image to an existing byte buffer regardless of the format (forcing it to ARGB in four bytes for instance), provided the buffer is big enough
-Read an image as a stream of uncompressed data, allowing for any memory management approach
I've looked around JAI and as far as I could tell none of these methods are available.
Thanks a lot if anyone can help!