我在这个程序中遇到了一个奇怪的错误,它从互联网上下载了一张照片,然后我将它转换为 .jpeg,然后我删除了第一张照片(以 .png 格式)。但我收到一个错误:文件正在被另一个进程使用。为什么会这样?我没有打开文件,也没有人使用它。
string outFile;
outFile = Path.GetTempFileName();
try
{
webClient.DownloadFile(foto, outFile);
if (foto.Substring(foto.Length - 3) == "png")
{
System.Drawing.Image image1 = System.Drawing.Image.FromFile(outFile);
foto = foto.Remove(foto.Length - 3) + "jpg";
string outFile2 = Path.GetTempFileName();
image1.Save(outFile2, System.Drawing.Imaging.ImageFormat.Jpeg);
System.IO.File.Delete(outFile);
outFile = outFile2;
}
}