1
我在我的VB项目中有一个功能,我扫描一个图像,然后我可以改变对比度。 我扫描并保存C:\temp\my_img.tif
。打开并保存问题
在winform
中,图像显示在PictureBox
中。
如果我在img.Save("C:\temp\my_img.tif", ImageFormat.Tiff)
的对比度函数集中得到了“GDI +中发生了一般性错误。”。但是,如果我将filename
设置为其他内容,则工作得很好。
那么,如何在保存之前释放使用过的图像呢?
的整体功能,简而言之:
Sub setContrast(ByVal C As Single)
'filename(1) ia a "global" variable that stores the used file path, in this case "C:\temp\my_img.tif"
Dim img As Image = Image.FromFile(filename(1)) '<--- I get the image
'A bunch of contrast stuff in some rows.....
'Here, i should release the image...
img.Save(filename(1), ImageFormat.Tiff) '<---Tries to save
PictureBox1.Refresh()
End Sub
这实际上并没有回答你的问题,但'Image'实现了'IDisposable',所以你应该在完成之后处置它,或者更好的是,将它放在'Using'块中。 –