gpt4 book ai didi

c# - 如何释放 BitMap 类持有的文件

转载 作者:太空宇宙 更新时间:2023-11-03 11:17:35 24 4
gpt4 key购买 nike

我有以下代码:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com