File in use with stream...

lidds

Well-known member
Joined
Nov 9, 2004
Messages
210
I am writing a image file to a stream and then add this to a picturebox using the following code:

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
 
The problem is the filestream isnt being closed in your code - it will keep the file locked until the garbage collector kicks in.

Try
Code:
 Converts comment image in zip file to bmp
Dim bmp As New Bitmap("C:\Orig.bmp")
Me.pictureBox.Image = bmp
as an alternate method.
 
Another more verbose option that should work is to define the filestream before your Bitmap() code and then do a filestream.close() after.

Code:
 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()
 

Similar threads

T
Replies
0
Views
567
This_display_name_is_already_in_use_They_all_are
T
E
Replies
0
Views
242
Eldeeb92
E
Back
Top