Images loading and preview
-
I'm currently writting an application and I need to load all images from a directory and display their thumbnails after. I'd need to change the preview list when the user click on another directory in the tree view, so I need to load those thumbnail fast. Currently I'm loading all those images one by one and I store them into an ImageList. I know this is not efficient and that the images stay open until the file handle is close. I'm worried about the possibility to run out of memory or of file handle if the garbage collector don't free those ressources soon enough. Do anybody have any idea how to handle efficiently images preview and loading in .Net 2.0? I've googled a lot, but didn't find anything doing it. In fast, I need an image viewer as fast as possible as I'm loading from memory card and other slow disk drive. Any idea? Let's discuss about .Net image capabilties.
-
I'm currently writting an application and I need to load all images from a directory and display their thumbnails after. I'd need to change the preview list when the user click on another directory in the tree view, so I need to load those thumbnail fast. Currently I'm loading all those images one by one and I store them into an ImageList. I know this is not efficient and that the images stay open until the file handle is close. I'm worried about the possibility to run out of memory or of file handle if the garbage collector don't free those ressources soon enough. Do anybody have any idea how to handle efficiently images preview and loading in .Net 2.0? I've googled a lot, but didn't find anything doing it. In fast, I need an image viewer as fast as possible as I'm loading from memory card and other slow disk drive. Any idea? Let's discuss about .Net image capabilties.
Ignore the garbage collector, you need to call Dispose on any image that you're throwing away. I believe it's possible to ask for a thumbnail when you call Bitmap.FromFile, or the constructor that takes a filename.
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
-
I'm currently writting an application and I need to load all images from a directory and display their thumbnails after. I'd need to change the preview list when the user click on another directory in the tree view, so I need to load those thumbnail fast. Currently I'm loading all those images one by one and I store them into an ImageList. I know this is not efficient and that the images stay open until the file handle is close. I'm worried about the possibility to run out of memory or of file handle if the garbage collector don't free those ressources soon enough. Do anybody have any idea how to handle efficiently images preview and loading in .Net 2.0? I've googled a lot, but didn't find anything doing it. In fast, I need an image viewer as fast as possible as I'm loading from memory card and other slow disk drive. Any idea? Let's discuss about .Net image capabilties.
Two comments: - there is at least one other thread (by RajeshGuptha) concerning a large app with many images; Rajesh ended up creating separate thumbnail files, so I guess he does not open a full image unless it is really needed. - I had some trouble with Image.FromFile keeping the file open (although the entire image has been loaded in memory). So I decided to immediately copy the image and dispose of the one returned by FromFile. And, of course, please make sure to dispose of everything that has a Dispose() method ! Cheers,
Luc Pattyn
-
Two comments: - there is at least one other thread (by RajeshGuptha) concerning a large app with many images; Rajesh ended up creating separate thumbnail files, so I guess he does not open a full image unless it is really needed. - I had some trouble with Image.FromFile keeping the file open (although the entire image has been loaded in memory). So I decided to immediately copy the image and dispose of the one returned by FromFile. And, of course, please make sure to dispose of everything that has a Dispose() method ! Cheers,
Luc Pattyn
Luc Pattyn wrote:
- I had some trouble with Image.FromFile keeping the file open (although the entire image has been loaded in memory). So I decided to immediately copy the image and dispose of the one returned by FromFile.
Yes, this is a known issue, a wrapper method that copies and closes the original is a good idea, if you may want to save over an image you've loaded and edited.
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert