Click here to Skip to main content
13,143,774 members (31,896 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I need to open several images from a folder and with every image I need to convert it to binary format. How can I open several files automatically within folder\sub folders?

Right Now I am able to open 1 file at a time by manually choosing form the openFileDialog.
openFileDialog1.FileName = "";
openFileDialog1.Title = "Images";           
openFileDialog1.Filter = "Png Images| *.png"; 
if (openFileDialog1.FileName.ToString() != "")
   Image.ImageLocation = openFileDialog1.FileName.ToString();
   img = new Bitmap(openFileDialog1.FileName.ToString());
Posted 9-Nov-12 9:17am
Updated 9-Nov-12 9:42am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you look closely at the OpenFileDialog class, you will see it has a Multiselect property[^] - set that to true and it will allow the user to select more than one file at a time. You can then use the Filenames property to open each image in a loop.

Do be aware however, that you should Dispose of Bitmap objects when you are finished with, don't just let them go out of scope or it will cause problems later.

BTW: You do not have to call ToString on string objects such as OpenFileDialog.FileName.
Marcus Kramer 9-Nov-12 15:42pm
+5. Excellent.
bmw318mt 9-Nov-12 15:56pm
I have hundreds of images in several sub folders that will be used to train a neural net, that is why I want to load the files one after the other automatically, instead of having the user selecting which files to open.
OriginalGriff 10-Nov-12 3:31am
Then do it with Directory.GetFiles - it has an overload which return subdirectory contents as well:
Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100