tags:

views:

18

answers:

1

I have an image list and would like to add a directory of images to the image list in my code. How would I do this? When I run the code:

'Load all of the items from the imagelist
For Each path As String In Directory.GetFiles("Images\LanguageIcons\")
     imlLanguagesIcons.Images.Add(Image.FromFile(path))
Next

I get an out of memory exception. Currently there is only 14 images so there really shouldn't be a problem. Any Help?

A: 

Like this

imageList.Images.Add(someImage);

Where someImage is an Image variable.

EDIT: Like this:

For Each path As String In Directory.GetFiles("Images\LanguageIcons")
    imageList.Images.Add(Image.FromFile(path))
Next
SLaks
But the file has can have a variable amount of image files. How do I add all of the items. I know how do what is above
muckdog12
What's the file?
SLaks
You may be looking for the `AddStrip` method.
SLaks
muckdog12
Do you mean that you're trying to add every image file in a folder? If so, loop over a call to `Directory.GetFiles`
SLaks
That is correct
muckdog12
You don't need to add `Directory.GetCurrentDirectory()`.
SLaks
I am not sure where the file is other that the fact that it should be in the current directory. If it is not it will throw and error
muckdog12
It threw a outofmemory exception
muckdog12
You said there are 14 images. What are their sizes and color depths? If I'm not mistaken, images loaded into an ImageList are uncompressed. So a 640x480 24bpp file will consume 921600 bytes. If your images are large, they could consume a large amount of memory.
Chris Dunaway
The largest size is 124x124. All of these images were already in the image list, but I deleted them because I want to do it in code because I want the user to be able to add thier own images into the file.
muckdog12