Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am writing a image file to a stream and then add this to a picturebox using the following code:

 

' Converts comment image in zip file to bmp
       Dim bmp As New Bitmap(New System.IO.FileStream("C:\Orig.bmp", FileMode.Open, FileAccess.Read))
Me.pictureBox.Image = bmp

 

The problem is that when I try to delete the file it gives me an error that the file is still in use. What I need to know is how I can release the image file.

 

Thanks in advance

 

Simon

  • Administrators
Posted

The problem is the filestream isn't being closed in your code - it will keep the file locked until the garbage collector kicks in.

 

Try

' Converts comment image in zip file to bmp
Dim bmp As New Bitmap("C:\Orig.bmp")
Me.pictureBox.Image = bmp

as an alternate method.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Another more verbose option that should work is to define the filestream before your Bitmap() code and then do a filestream.close() after.

 

' Converts comment image in zip file to bmp
Dim fs as New System.IO.FileStream("C:\Orig.bmp", FileMode.Open, FileAccess.Read)
Dim bmp As New Bitmap(fs)
Me.pictureBox.Image = bmp
fs.Close()

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...