I want to preload (load into memory) about 10 jpg pictures (size 3264px x 2448px). Each image filesize is ~3MB. I've tried to load them into ArrayList of BufferedImage but I get OutOfMemoryError Exception (Java heap space). How to cope with it?
Each image filesize is ~3MB. I've tried to load them into ArrayList of BufferedImage but I get OutOfMemoryError Exception (Java heap space). How to cope with it?
Each compressed image size is 3MB. As you wrote in your title, 3264*2448 is 7 990 272 pixels (about 8Mpix). Using the common ARGB that's 32 bits per pixel, or about 32 MB per picture.
If you want to preload these 10 pictures uncompressed (for example in ten BufferedImage), you'll need 320 MB of memory for these 10 pictures only.
So you'd need to run your java application with more memory.
..any possibility to store image in compressed form?
Sure, load them as byte arrays & keep a reference to each (3 Meg) array. As you require each actual image, stamp it out to an image by wrapping it in a ByteArrayInputStream and use that as the source to ImageIO.read(InputStream).
That would come to around 30 Meg for the 10 byte[], and 321 meg for each realized image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With