C#Newbie01

This may be a stupid question, but I have been playing around with this for over a week and haven't gotten anything that even remotely works (Or for that matter appears to do anything). I have a folder on my computer, and would like to load all the images meeting a certain naming convention (i.e. "1_0001.jpg", "1_0002.jpg", etc.) into my program. I added a bunch of buttons and would like the images to show as thumbnails on the buttons. All images named something like 2_0001.jpg, etc. would show up in a different place. I can't get the application to look at all of the files of a specific type of name, or to show thumbnails. I would really appreciate some help, as I am really lost.

Thank you very much.


Re: Visual C# Express Edition Can I Load all Images in a range in a folder as ThumbNails?

Brendan Grant

How do you intend to display the images to the screen With an ImageList Manually painting

The first thing you¡¯ve got to do is get the file names... and probably the easiest way to do that would be to use the Directory.GetFiles() method which by default will give you a string array of all of the files in the specified directory.

It¡¯s got an overload though, one that will take a filter expression (not unlike the sort that Windows Search uses (ie wildcards))... so take the following code:

Code Snippet

string[] files = System.IO.Directory.GetFiles(@"C:\Some Directory\", "1_ .jpg");

foreach (string file in files)

{

Image i = Image.FromFile(file);

//Do something with the image

}

When this executes, a list of all of the files in C:\Some Directory\ which match the pattern ¡®1_ .jpg¡¯

Remember that the windows Wildcard character means substitute any single character, so the above call will return all files with a ¡®1_¡¯ followed by exactly four characters and then a ¡®.jpg¡¯

Is this what you are looking for






Re: Visual C# Express Edition Can I Load all Images in a range in a folder as ThumbNails?

C#Newbie01

Thank you very much, that is exactly what I'm looking for. I have been searching online for over a week for a way to do that and had no luck whatsoever. Thank you very much.

To answer your question, I would like to then load each image in the image property of a button as a resized thumbnail. I would then like the user to be able to click on the image and bring up another form displaying a larger version of the appropriate image. There seems to be a lot of different ways to create a thumbnail image, and I'm not sure which is best. As the suggested code you provided is loading all of the images into memory, would I be able to just resize the images, or would I need to do something more When I click on the image, how will my application know which image I selected I'm not very sure how this would work.

Thank you very much.




Re: Visual C# Express Edition Can I Load all Images in a range in a folder as ThumbNails?

Brendan Grant

With the code above you could simply assign a button¡¯s Image property to the loaded image¡­ and even manually resize the image before that assignment.

One other option you might consider is using an ImageList instance to store all of the images and then use that as your centralized image store which also can handle the resizing for you. The one drawback of using an ImageList though is that you are limited in terms of what sizes you can use (maximum of 256x256).






Re: Visual C# Express Edition Can I Load all Images in a range in a folder as ThumbNails?

C#Newbie01

Thank you very much, I will take a look into your suggestions.

Thank you very much.