![]() |
|
[.NET] Adding images to array from folder - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] Adding images to array from folder (/showthread.php?tid=5567041) |
Adding images to array from folder - SIM-1517404 - Mar 5, 2017 Hi, I was wondering if it's possible to add all images in a folder to an array in my project? The amount of images in the folder will change. * - SIM-1517404 - Mar 5, 2017 (Mar 5, 2017 08:46 AM)Orka Wrote: Yes it is possible, but I recommend storing their absolute paths instead of array of graphic/bitmaps. So have a string array with their paths ? Having the path stored in arrays would work, but I don't want to manually add the path to every image. I want to loop through the folder, adding all available images. I might also in the future want to read files from a database. * - +Haze - Mar 5, 2017 What is your goal, what are you trying to do after you've got an array of the images? * - SIM-1517404 - Mar 5, 2017 (Mar 5, 2017 09:52 AM)+Haze Wrote: What is your goal, what are you trying to do after you've got an array of the images? They are panorama images, so I'm loading them in a panorama viewer engine. * - Lucasheer - Mar 5, 2017 I wrote a few examples along with how you can possibly get the image paths you want. If Bitmaps are what you want, and you don't have too many images, then you might want to use Example 1, and dispose them afterwards. OR, if you have many images, and you can dispose as you use, then use Example 2. The panorama engine might even have some way to load images via string paths instead of actual images in memory, if that makes sense. Code Private Function GetImagePaths() As String() 'You could use .Where, with EnumerateFiles. But this builds a list of files with ending of .jpg or .png (might want to modify the strings IDK)* - Ninja - Mar 5, 2017 Loading in all images at once can be heavy on your machine depending on how many you load in at once. * - SIM-1517404 - Mar 5, 2017 (Mar 5, 2017 10:06 AM)Lucasheer Wrote: I wrote a few examples along with how you can possibly get the image paths you want. If Bitmaps are what you want, and you don't have too many images, then you might want to use Example 1, and dispose them afterwards. OR, if you have many images, and you can dispose as you use, then use Example 2. The panorama engine might even have some way to load images via string paths instead of actual images in memory, if that makes sense. I don't want to dispose of the images as they are used, because they might be used again. If I can store the file paths in an array, that would probably be better as the engine loads images from a path, but this can of course be modified. The amount of images will range anywhere from 10 to maybe up to 50. * - Visual Freedom - Mar 5, 2017 I suggest you to load only a few images into the ram and do not keep all in RAM due performance and resource use. * - Owl - Mar 5, 2017 (Mar 5, 2017 09:55 AM)Swatchi Wrote: They are panorama images, so I'm loading them in a panorama viewer engine. Here is my suggestion Code var imgs = Directory.GetFiles(@"path", "*.png");As you can see it loads only 1 image into memory at a time (image fromfile) * - SIM-1517404 - Mar 5, 2017 (Mar 5, 2017 01:14 PM)Orka Wrote: Here is my suggestion I don't need to draw the image, the engine does that for me, I just need to store the paths in an array so that for different situations I can change the filepath for the engine. :) I've come to the conclusion that the best way to do this is to store the paths and not the images, although storing the paths take away the opportunity to directly access the filename, but it'll have to do :D Do you know how to do this? I guess it's really just to get the file name of every element in a folder at this point. * - SIM-1517404 - Mar 5, 2017 (Mar 5, 2017 01:43 PM)Orka Wrote: Oh.. Anyway yes also possible Does this grab the name of all the files ? Or one at a time ? So that I can loop through an array and assign a filename to each spot ? * - SIM-1517404 - Mar 5, 2017 (Mar 5, 2017 02:00 PM)Orka Wrote: My code will return a collection of file names. I don't understand what you mean on how to use it. "Directory.GetFiles(@"path", "*.png").Select(f => Path.GetFileNameWithoutExtension(f));" Where are the file names stored ? In an array or ? * - SIM-1517404 - Mar 5, 2017 (Mar 5, 2017 02:35 PM)Orka Wrote: Ah ok, thank you ! :) |