我这里有一个简单的代码:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Button 1
PictureBox1.Image = Image.FromFile("D:\1.jpg")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Button 2
PictureBox1.Image = Nothing
IO.File.Delete("D:\1.jpg")
End Sub
当我按下按钮1从文件导入图像然后我想按下按钮1后删除此图像有一个错误“进程无法访问文件'D:\ 1.jpg',因为它正被使用另一个过程。“
当我按下按钮2,任何解决方案时都会发生错误?
(编辑):解决方案unable to delete image after opening it in vb.net app
答案 0 :(得分:1)
Image.FromFile
方法锁定文件,直到放置Image
对象。将Image
的{{1}}属性设置为PictureBox
不会释放Nothing
对象。你需要明确地这样做:
Image