【发布时间】:2013-01-22 14:11:57
【问题描述】:
我的 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,所以你应该在完成后将其丢弃,或者更好的是,将其放入@987654329 @块。
标签: vb.net winforms bitmap gdi+