# Loading large amount of image files

**URL:** <https://discourse.processing.org/t/loading-large-amount-of-image-files/23971>\
**Category:** Coding Questions\
**Created:** [September 19, 2020, 10:37pm UTC](https://discourse.processing.org/t/loading-large-amount-of-image-files/23971 "2020-09-19T22:37:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [September 19, 2020, 10:37pm UTC](https://discourse.processing.org/t/loading-large-amount-of-image-files/23971/1 "2020-09-19T22:37:25Z")

</div>

I have made an image viewer unfortunately it isn’t really efficient. I can only load a maximum of around 60 medium resolution images, anything high rez or in larger volumes and the program suffers from memory errors.

My question is what is the best approach for this situation and how is it normally handled in image viewer which can at the very least open folders with 100+ files and provide thumbnails.

For clarification, the method I was using was simply loadImages(), then saving the loaded image into an array then resizing said image and saving that for the thumbnail. However as I said not very efficient.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 20, 2020, 5:16am UTC](https://discourse.processing.org/t/loading-large-amount-of-image-files/23971/2 "2020-09-20T05:16:49Z")

</div>

> [@paulgoux](#):
>
> , then saving the loaded image into an array…

If Java can’t allocate that much RAM don’t load everything at once!

Instead collect all paths via [**listPaths()**](http://processing.github.io/processing-javadocs/core/processing/core/PApplet.html#listPaths-java.lang.String-java.lang.String...-), then **loadImage()** + **resize()** + **save()** 1 by 1 inside a loop:

> [@File Listing Order](https://discourse.processing.org/t/file-listing-order/7148/41):
>
> [Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/util/Arrays.html#sort(java.lang.Object[])](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/util/Arrays.html#sort(java.lang.Object%5B%5D)) static final String PICS\_EXTS = "extensions=,png,jpg,jpeg,gif,tif,tiff,tga,bmp,wbmp"; static final float FPS = .25; PImage[] images; void setup() { size(1200, 600); frameRate(FPS); imageMode(CENTER); final File dir = dataFile(""); println(dir); String[] imagePaths = {}; int imagesFound = 0; if (dir.isDirectory()) { imagePaths = listPaths(dir.getPath(), "files", "recursi…
