JPG file being kept as accessed by program

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • Re: Bitmap class problem
    ... > I'm using the Image.FromImagefunction to load a jpg file into a bitmap ... > class and then convert it to a lower resolution. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do I create an icon file from a jpeg?
    ... standard file folder. ... and find one that will load a .jpg file and make a .ico file from it. ...
    (microsoft.public.office.misc)
  • Re: Black Eyed Peas
    ... it's "X-ed" in my IE, and the direct link to the ..jpg file takes ages to load and it has not loaded yet. ... Cillit BANG ...
    (rec.music.hip-hop)
  • Re: Picture.LoadFromFile
    ... >I have Delphi 5 Enterprise. ... I have a TImage that I want to load a JPG file ... When I use the Image Editor (by double-clicking the TImage at design ...
    (alt.comp.lang.borland-delphi)