How to load three thousand(or more) of images from external folder?

Hi All,
I am a beginner and working on a project that uses a lot of images, like 3000,which are vary in size.The function is to randomly select 500 images to display on the screen at regular intervals, and each image has an entry and exit animation.
When I load all the images and save them when the program starts, memory will be used too much.Besides when I use coroutine to load the images that need to be displayed on each screen without affecting the running of the current software, it will take too long.For example, it takes about 25 seconds to load 500 images, but we have to get these in five seconds.Perhaps there are other ways to do this.
Thanks for any help!

How many of them do you want to be on the screen at the same time? If only a few, you can just get the list of files from the folder, and load the textures before you’re going to show them. Then destroy them when they become invisible (i mean the generated texture, not the actual file). More info here. If you mean you want to show all of them at once like a mosaic then it’s going to be tough. 500 images are a lot, you would need to optimize it with maybe a custom shader and texture arrays if the target platform permits it. Other than that you can downsize the textures and combine them into an atlas and create sprites from them but this may be even slower than your original code (Increase first loading time but the program would run faster after that) Using multiple threads to split the work could also help… I would need more info on how you want to use them to be able to help better.

Hello there. Instead of loading them all and selecting some random ones, you can load the paths and pick some random ones from the paths like following:

using System.IO; //Must be included

                string path = @"YOUR PATH";
                var ps = Directory.GetFiles(path);
                Random rand = new Random();
                List<string> pf = new List<string>();
                for (int i = 0; i < AMOUNTOFIMAGESYOUWANTTOHAVEINUNITY; i++)
                {
                    pf.Add(ps[rand.Next(0, ps.Length)]);
                }
                List<Texture2D> textures = new List<Texture2D>();
                foreach (var item in pf)
                {
                    Texture2D t = new Texture2D(2, 2); //The size doesn't matter as loading the image will change the values.
                    t.LoadImage(File.ReadAllBytes(item));
                    textures.Add(t);
                }

Now you will have a list of textures that have been randomly selected.

As other poeple said, you should save the photos to a local folder, and only load the photos you need.

However, i would like to mention an edit that i have used in my old plugin (Photo Mosaic). To improve the performance, my script bakes the loaded 256 photos into one RenderTexture. It sacrifices the resolution of each photo (512x512 each for 8k texture res limit). but it highly improves the performance by reducing drawcalls.

Following this idea, you probably can render all 3000 photos in just 12 drawcalls, with 12 8k RenderTextures