Displaying many image files without going out of memory?

I am trying to make an app which will display all the image files’ pictures in a scrolling window(of ofxImGui). The first problem was, it was very slow to load the pictures into ofImage objects.That problem partially got fixed using ofxThreadedImageLoader.

But now there is another problem and I am not sure how I can fix it.
If the selected directory using the app has high resolution pictures(for example: photos taken by a not very old Android phone) , it is able to load and display 20 image files, but if I try to display for example 40 image files, then the screen of my Android phone goes black blank, but if Ithe directory has low-resolution images, , then it can load and display more than 40 image files without problem.So I think I am hitting a limit of ram.

Even if I can somehow optimize memory usage of the app, it would not be able to solve the problem because the directory of the image files (which is selected using the app) may have more than 1000 picture files,for example and no matter how I optimize the memory usage of the app, it will crash to a limit of ram when it tries to display them.

What can I do in this case? Thanks

Note: I am testing the app on a Sony Xperia XA1 Ultra Android phone.

Hi, you need to load and unload images on the fly. you can have loaded only the images that are actually on screen and maybe the previous and following ones. As you scroll you load new ones and unload the old ones. In order to reduce memory usage you can resize the images if there are too large when loaded.
I’d rather use some already made solution for thing. Most probably the OS might have a system for displaying images as you describe, and only if you cant find such you should implement this with OF

1 Like

Thanks for your answer.

Resizing images after loading worked nice, now it can load and display much more images.Loading images from files is slow for both using ofImage’s load() function and ofxThreadedImageLoader, loading and displaying one image takes about 2-3 seconds.I think it needs to load the images with a smaller resolution/size while loading them from the image files, is it possible to do it without using Jni calls?Or maybe another way to make the loading process quicker?

Loading from disk is always a slow process.
You can have the app to make some sort of cache of thumbnails, preprocess these somehow.
I have not done any Android development in a long time so I can not really tell. As I said, there might be an already built gallery widget on androind that you could use along side with your ofApp. (I’ve done some stuff like that in the past, but I dont recall how. What I mean, is that it is possible).

1 Like

Thanks for your answer.