lidds Posted March 6, 2008 Posted March 6, 2008 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 Quote
Administrators PlausiblyDamp Posted March 7, 2008 Administrators Posted March 7, 2008 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nate Bross Posted March 8, 2008 Posted March 8, 2008 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() Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.