L
Lloyd Sheen
I have a problem in a program in which a jpg file which is being used to
load the Image of a picturebox is being kept after the load.
The code is as follows:
Public ReadOnly Property ImageUrl() As Image
Get
If theImage Is Nothing Then
Dim jpgs() As String = Directory.GetFiles(Me.FolderName, "*.jpg")
If jpgs.Length > 0 Then
Try
Dim theTempImage As Image = Image.FromFile(jpgs(0))
theImage = CType(theTempImage.Clone, Image)
theTempImage.Dispose()
'theImage = Image.FromFile(jpgs(0))
Catch ex As Exception
Dim x As Integer = 1
Return Nothing
End Try
Return theImage
Else
Return Nothing
End If
Else
Return theImage
End If
End Get
End Property
As you can see I tried to get rid of the problem by cloning the first
image and then disposing it to get rid of the "reference" to the jpg
file. That does not work.
The problem occurs in the app if I attempt to delete the folder while it
is being shown in a list (the ImageURL property is used for databinding).
Any ideas on how to load the image without keeping a reference to the file?
Thanks
LS
load the Image of a picturebox is being kept after the load.
The code is as follows:
Public ReadOnly Property ImageUrl() As Image
Get
If theImage Is Nothing Then
Dim jpgs() As String = Directory.GetFiles(Me.FolderName, "*.jpg")
If jpgs.Length > 0 Then
Try
Dim theTempImage As Image = Image.FromFile(jpgs(0))
theImage = CType(theTempImage.Clone, Image)
theTempImage.Dispose()
'theImage = Image.FromFile(jpgs(0))
Catch ex As Exception
Dim x As Integer = 1
Return Nothing
End Try
Return theImage
Else
Return Nothing
End If
Else
Return theImage
End If
End Get
End Property
As you can see I tried to get rid of the problem by cloning the first
image and then disposing it to get rid of the "reference" to the jpg
file. That does not work.
The problem occurs in the app if I attempt to delete the folder while it
is being shown in a list (the ImageURL property is used for databinding).
Any ideas on how to load the image without keeping a reference to the file?
Thanks
LS