By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,578 Members | 1,786 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,578 IT Pros & Developers. It's quick & easy.

ListViewImageList keeps bitmap locked after disposing

P: n/a
Hello,

I have a listview with an image list. After dispoing the images and the
image list, the bitmap files remain locked:

REM Create.
objImage = Image.FromFile(strBmp)
If Me.lsvTest.LargeImageList Is Nothing Then
Me.lsvTest.LargeImageList = New ImageList()
End If
Me.lsvTest.LargeImageList.Images.Add(objImage)
objLVI = Me.lsvTest.Items.Add(strBmp)
objLVI.ImageIndex = Me.lsvTest.LargeImageList.Images.Count - 1
objImage = Nothing

REM Delete.
For Each objImage In Me.lsvTest.LargeImageList.Images
objImage.Dispose()
objImage = Nothing
Next
Me.lsvTest.LargeImageList.Images.Clear()
Me.lsvTest.LargeImageList.Dispose()
Me.lsvTest.LargeImageList = Nothing
Me.lsvTest.Items(Me.lsvTest.Items.Count - 1).Text = "Disposed"

REM Bitmap file remains locked.
objInfo.Open(IO.FileMode.Open).Close() ' Gives exception.

Why do the bitmap files remain locked?

Thanks
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

Use image.fromstream to keep the file from being locked.

Dim fsImage As New IO.FileStream("C:\Test.jpg", IO.FileMode.Open)

Dim objImage As Image = Image.FromStream(fsImage)

fsImage.Close()

Ken

---------------------

"Qwert" <no**@nosp.com> wrote in message
news:Q6********************@casema.nl...
Hello,

I have a listview with an image list. After dispoing the images and the
image list, the bitmap files remain locked:

REM Create.
objImage = Image.FromFile(strBmp)
If Me.lsvTest.LargeImageList Is Nothing Then
Me.lsvTest.LargeImageList = New ImageList()
End If
Me.lsvTest.LargeImageList.Images.Add(objImage)
objLVI = Me.lsvTest.Items.Add(strBmp)
objLVI.ImageIndex = Me.lsvTest.LargeImageList.Images.Count - 1
objImage = Nothing

REM Delete.
For Each objImage In Me.lsvTest.LargeImageList.Images
objImage.Dispose()
objImage = Nothing
Next
Me.lsvTest.LargeImageList.Images.Clear()
Me.lsvTest.LargeImageList.Dispose()
Me.lsvTest.LargeImageList = Nothing
Me.lsvTest.Items(Me.lsvTest.Items.Count - 1).Text = "Disposed"

REM Bitmap file remains locked.
objInfo.Open(IO.FileMode.Open).Close() ' Gives exception.

Why do the bitmap files remain locked?

Thanks

Nov 21 '05 #2

P: n/a
Yeah I tried it but it gives errors when I use that trick with
listview.imagelist. In other cases it works.

"Ken Tucker [MVP]" <vb***@bellsouth.net> schreef in bericht
news:OZ****************@TK2MSFTNGP12.phx.gbl...
Hi,

Use image.fromstream to keep the file from being locked.

Dim fsImage As New IO.FileStream("C:\Test.jpg", IO.FileMode.Open)

Dim objImage As Image = Image.FromStream(fsImage)

fsImage.Close()

Ken

---------------------

"Qwert" <no**@nosp.com> wrote in message
news:Q6********************@casema.nl...
Hello,

I have a listview with an image list. After dispoing the images and the
image list, the bitmap files remain locked:

REM Create.
objImage = Image.FromFile(strBmp)
If Me.lsvTest.LargeImageList Is Nothing Then
Me.lsvTest.LargeImageList = New ImageList()
End If
Me.lsvTest.LargeImageList.Images.Add(objImage)
objLVI = Me.lsvTest.Items.Add(strBmp)
objLVI.ImageIndex = Me.lsvTest.LargeImageList.Images.Count - 1
objImage = Nothing

REM Delete.
For Each objImage In Me.lsvTest.LargeImageList.Images
objImage.Dispose()
objImage = Nothing
Next
Me.lsvTest.LargeImageList.Images.Clear()
Me.lsvTest.LargeImageList.Dispose()
Me.lsvTest.LargeImageList = Nothing
Me.lsvTest.Items(Me.lsvTest.Items.Count - 1).Text = "Disposed"

REM Bitmap file remains locked.
objInfo.Open(IO.FileMode.Open).Close() ' Gives exception.

Why do the bitmap files remain locked?

Thanks

Nov 21 '05 #3

P: n/a
Turned out if you use the 'stream' trick to load graphics files for
list.imagelist, and you set the 'TransparentColor' property of the
ImageList, you get "Out of memory" exceptions. If you don't use that
property, things work. Have no idea why this happens.


"Qwert" <no**@nosp.com> schreef in bericht
news:Q6********************@casema.nl...
Hello,

I have a listview with an image list. After dispoing the images and the
image list, the bitmap files remain locked:

REM Create.
objImage = Image.FromFile(strBmp)
If Me.lsvTest.LargeImageList Is Nothing Then
Me.lsvTest.LargeImageList = New ImageList()
End If
Me.lsvTest.LargeImageList.Images.Add(objImage)
objLVI = Me.lsvTest.Items.Add(strBmp)
objLVI.ImageIndex = Me.lsvTest.LargeImageList.Images.Count - 1
objImage = Nothing

REM Delete.
For Each objImage In Me.lsvTest.LargeImageList.Images
objImage.Dispose()
objImage = Nothing
Next
Me.lsvTest.LargeImageList.Images.Clear()
Me.lsvTest.LargeImageList.Dispose()
Me.lsvTest.LargeImageList = Nothing
Me.lsvTest.Items(Me.lsvTest.Items.Count - 1).Text = "Disposed"

REM Bitmap file remains locked.
objInfo.Open(IO.FileMode.Open).Close() ' Gives exception.

Why do the bitmap files remain locked?

Thanks

Nov 21 '05 #4

P: n/a
Ken,

"Ken Tucker [MVP]" <vb***@bellsouth.net> schrieb:
Use image.fromstream to keep the file from being locked.

Dim fsImage As New IO.FileStream("C:\Test.jpg", IO.FileMode.Open)

Dim objImage As Image = Image.FromStream(fsImage)

fsImage.Close()


.... notice that the stream must be kept open as long as the 'Image' object
is not disposed.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.