Question Display Image Thumbnail in List View

ahbutt

New member
Joined
Jan 3, 2011
Messages
4
Programming Experience
1-3
Hi Everyone,


Currently i'm working on a program that required to display all the images of a folder into the screen. I make use of ImageList & List View to get my job done.


Everything is smooth until the programs hits the "OUT OF MEMORY" Error. I have struggled with this error for couple of days. Anyone Kindly help ? Thanks First..

=======
Code
=======

Dim imlTemp As New ImageList
Dim dirFiles() As String = IO.Directory.GetFiles("D:\ImagesFolder")
Dim _imgList As New ImageList
Dim imgSize As New Size

imgSize.Width = 150
imgSize.Height = 150

ListView2.LargeImageList = _imgList

Dim count As Integer = 0
Dim item As New ListViewItem

For Each dirFile As String In dirFiles

For Each extension As String In allowedExtensions
If extension = IO.Path.GetExtension(dirFile) Then

Dim img As New System.Drawing.Bitmap(dirFile)

_imgList.ImageSize = imgSize
_imgList.Images.Add(img.Clone)

ListView2.Items.Add(dirFile, count)
count += 1

End If
Next
Next



Everything is working fine, if the images in a folder is less than abt 8Mb. Anyone could help ?
 
_imgList.Images.Add(img.Clone)
change to:
VB.NET:
_imgList.Images.Add(img)
img.Dispose()
This removes the creation of an additional clone copy of the full size image in memory, and equally important disposes the full size image when done with it.
 
Thanks for your reply...but i tried it here...it still hit the out Of Memory error... any others suggestion / solution ?
 
i found the solution d, the out of memory occured due to the large image dimension (1275x1400 - roughly) i add into the ImageList, i have tried to add in 200mb++ with small dimension, it working perfectly d, Thanks for the helps....
 
According to the code you posted you had 150x150 image size in ImageList. Images of any size are automatically resized to that when they are added.
 
nice code
but can you realize that the img that added is in a low quality
just not like the real file quality
i mean that from dirfile

have any solution ??;);)
 
Back
Top