I'm creating a java program that uses multiple images to create animations and I am looking for the best way to read/load images with ImageIO without using a lot of memory.
I've noticed in a similar post getSubimage() is mentioned as a way to improve performance: Using several bufferedImages in java
My question is: based on the way java ImageIO handles images, is it better to have a few extremely large grouped images and use getSubimage() to separate them (possibly as large as 100,000 pixels by 100,000 pixels because the program uses several scrolling backrounds), split every image into the smallest possible size and load them individually, or a combination of the two. I am currently grouping the smaller images and loading them as one image, but loading larger images individually. Performance varies anywhere from loading in a few seconds to nearly crashing my laptop and forcing me to reboot.
I was wondering if anybody could provide reasoning - if possible in terms of Big O Efficiency - for the benefits of loading many small images versus benefits of loading a few massive images. Does ImageIO loading work like a sort algorithm - where (given the right sort) it can become exponentially slower as size increase, but if broken into sub sets can be tackled fairly quickly?
The Oracle documentation for ImageIO.read(File input) is as follows:
Returns a BufferedImage as the result of decoding a supplied File with an ImageReader chosen automatically from among those currently registered. The File is wrapped in an ImageInputStream. If no registered ImageReader claims to be able to read the resulting stream, null is returned.
I could not find any other indication of how ImageIO actually processes the images. Thank you in advance for any clarification of how this works. If question is too broad or off-topic let me know and I will revise/delete.