473,372 Members | 1,047 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

ListView and ImageList hogging memory - what to do?

I am working on an application that includes a feature where a
directory is spidered and thumbnails are displayed. I have it pretty
much down, but when the bitmaps are loaded from file, memory is hogged
like crazy. I know this is where the memory problems occur because
I've gone through that whole comment/check the ram thing. Here's the
source of where the problem occurs:

Public Shared Sub FillImageList(ByVal dir As String, ByVal ListView As
ListView)
If Directory.Exists(dir) Then
'Get the files in an array and
'figure out how many there are
Dim file As String
Dim files() As String = Directory.GetFiles(dir)
Dim cleanfiles(files.Length) As String
Dim i As Integer = 0
For Each file In files
If Regex.IsMatch(file.ToString,
"[^<.*>.*](.jpg|.JPG|.jpeg|.JPEG|.png|.PNG|.gif|.GIF|.tif|.T IF|.bmp|.BMP)")
Then
cleanfiles(i) = file.ToString
i = i + 1
End If
Next

'Create a thumbnail for every image and add it to the
imagelist
If cleanfiles.Length > 0 And cleanfiles(0) <> "" Then
Dim h As Integer = 0
For Each file In cleanfiles
If file <> "" Then
'###BEGIN MEMORY LEAK
Dim objImage As Image
' Open the image
objImage = New Bitmap(file)
'###END MEMORY LEAK

' Convert the image to a thumbnail. This is
faster
' than the longer convert/compress to JPEG I
was
' using before.
objImage = objImage.GetThumbnailImage(100,
100, Nothing, New IntPtr)

'Add the thumbnail to the image list
ListView.LargeImageList.Images.Add(objImage)
'Add the filename as the text
ListView.Items.Add(file.ToString)
'Attach the image to the text
ListView.Items(h).ImageIndex = h
h = h + 1
objImage.Dispose()
End If

Next
End If
End If
End Sub
Any help would be very greatly appreciated. Reply here or email
pu****@putnamplanet.com. Thanks!

-C
Nov 20 '05 #1
0 2220

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Randy Birch | last post by:
Reposted as the original is reported as deleted from the server. re: MSComCtl Listview control cashes after installing VB6/VS6 SP6 I have been advised that this problem has been reproduced...
0
by: Silvia | last post by:
Hi, I have a program that capture images and put this into a listview (using imagelist), the problem is when I delete de image the listview, when do that and capture another image, the image...
3
by: Ian | last post by:
Hi, I've been trying to create a listview and treeview with icons. You would think it's a pretty straight forward task. API documentation states you simply assign an ImageList - that's been...
0
by: Silvia | last post by:
Hi, I have a program that capture images and put this into a listview (using imagelist), the problem is when I delete de image the listview, when do that and capture another image, the image...
1
by: Mamatha | last post by:
Hi I have one application ,that diplays data from database into the listview control.While adding data to the listview i want to display an icon to the leftside of the first column's data.Here...
2
by: GT | last post by:
Could someone please explain how to add images to a ListView other than in the first column?
1
by: Steve | last post by:
OK, I am stumped. I cannot for the life of me get images to show in ListView items while the view is set to Details. I create an ImageList, set the SmallImageList to point to the ImageList, then...
4
by: Archimed | last post by:
Hi, I try to use an ImageList with a ListView but that don't work. I make a ListView in VirtualMode with LargeIcon view. I put the ImageList in the LargeImageList property. I add a bitmap...
2
by: witpo | last post by:
Hi, I would like to display all listview items in one row with scroll bar below it instead of multiple rows and scroll bar on the right. Someone told me that I can achieve it using...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.