Close file open as an image in Picturebox
-
Hi, I have inserted an image from an existing file which I want to close. I have tried using dispose() command (shown below); however it gives an error. Could some one suggest what would be the command to close the file after the image has been displaced? Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click 'Temperature button pressed Dim iImage As Image iImage = Image.FromFile("C:\Aman\ZedGraph\temp.jpeg") 'PictureBox1.Image = Image.FromFile("C:\Aman\ZedGraph\temp.jpeg") PictureBox1.Image = iImage iImage.Dispose() End Sub Thanks Aman
-
Hi, I have inserted an image from an existing file which I want to close. I have tried using dispose() command (shown below); however it gives an error. Could some one suggest what would be the command to close the file after the image has been displaced? Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click 'Temperature button pressed Dim iImage As Image iImage = Image.FromFile("C:\Aman\ZedGraph\temp.jpeg") 'PictureBox1.Image = Image.FromFile("C:\Aman\ZedGraph\temp.jpeg") PictureBox1.Image = iImage iImage.Dispose() End Sub Thanks Aman
The problem is you're using Image.FromFile to load the image. This will lock the file for the lifetime of the Image object. Instead, you want to do this:
Dim pic As Bitmap
Using fs As New FileStream("C:\Aman\ZeqGraph\temp.jpeg", FileMode.Open, FileAccess.Read)
pic = New Bitmap(fs)
End Using
PictureBox1.Image = picA guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
The problem is you're using Image.FromFile to load the image. This will lock the file for the lifetime of the Image object. Instead, you want to do this:
Dim pic As Bitmap
Using fs As New FileStream("C:\Aman\ZeqGraph\temp.jpeg", FileMode.Open, FileAccess.Read)
pic = New Bitmap(fs)
End Using
PictureBox1.Image = picA guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
The problem is you're using Image.FromFile to load the image. This will lock the file for the lifetime of the Image object. Instead, you want to do this:
Dim pic As Bitmap
Using fs As New FileStream("C:\Aman\ZeqGraph\temp.jpeg", FileMode.Open, FileAccess.Read)
pic = New Bitmap(fs)
End Using
PictureBox1.Image = picA guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Wasn't this just asked? LOL.
Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison
Yep, Jan 2 by TheComputerMan. Amazing, noone ever actually reads the forums...
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008