File handling

cjohnson

Well-known member
Joined
Sep 21, 2006
Messages
63
Location
WV
Programming Experience
1-3
I have a quick question. I am importing a picture to use in a picturebox with the following code.

VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] im [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Image = Bitmap.FromFile([/SIZE][SIZE=2][COLOR=#800000]"pic.jpg"[/COLOR][/SIZE][SIZE=2])
PictureBox.Image = im
[/SIZE]

Then, later in the program, I want to replace the file pic.jpg with another file, but I can not because the program is still using pic.jpg. Can someone tell me how to 'release' this file once I have loaded it and set the picturebox?

Thanks,
Chris
 
if I remember correctly from previous posts asking about this, set the Picturebox's image property to nothing should release the last reference to the image:
PictureBox.Image = Nothing
 
If you need to still be displaying the same image after the source file is changed you can load it with stream something like this:
VB.NET:
Dim filename As String = "c:\test.jpg"
PictureBox1.Image = Image.FromStream(New IO.MemoryStream(My.Computer.FileSystem.ReadAllBytes(filename)))
 

Latest posts

Back
Top