|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ListViewImageList keeps bitmap locked after disposingI 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 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" <n***@nosp.com> wrote in message I have a listview with an image list. After dispoing the images and thenews:Q6Cdnf7pPYvtUtvfRVnyrw@casema.nl... Hello, 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 Yeah I tried it but it gives errors when I use that trick with
listview.imagelist. In other cases it works. Show quoteHide quote "Ken Tucker [MVP]" <vb***@bellsouth.net> schreef in bericht news:OZ%23y$SvMFHA.3356@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" <n***@nosp.com> wrote in message > news:Q6Cdnf7pPYvtUtvfRVnyrw@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 > > > Ken,
"Ken Tucker [MVP]" <vb***@bellsouth.net> schrieb: .... notice that the stream must be kept open as long as the 'Image' object > 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() is not disposed. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> 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. Show quoteHide quote "Qwert" <n***@nosp.com> schreef in bericht news:Q6Cdnf7pPYvtUtvfRVnyrw@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 >
Timer1_Elapsed problem.
Locate MessageBox over Window Error with Custom Control what if the database connection isn't close MaskedEdit Control Friend WithEvents Upload file programmatically DataGrid OnPaint/? -How Do I Draw A GDI Type Circle On Top Of A DataGrid FileSystemWatcher: Fix for lowercase? add-in missing from toolbar. |
|||||||||||||||||||||||