我有以下代码:
Bitmap image = new Bitmap(filePath);
...
image.Save(someOtherPath);
image.Dispose();
File.Delete(filePath);
File.Move(someOtherPath, filePath);
File.Delete 行引发以下错误:
The process cannot access the file '...' because it is being used by another process.
如何让 C# 释放它对文件的锁定?
最佳答案
尝试
using(var image = new Bitmap(filepath))
{
image.Save(someOtherPath);
}
File.Delete(filePath);
File.Move(someOtherPath, filePath);
关于c# - 如何释放 BitMap 类持有的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12174004/