我在图片文件夹中有一个名为image1.jpg的图像文件。此图像文件受zip保护,密码为1234.我需要将此图像加载到我的C#winform应用程序中;所以我必须解压缩此图像,加载它然后再次删除image1.jpg。我的问题是,即使在加载图像后我的C#应用程序在删除它时也没有显示图像。如果我删除" File.Delete(...."如你所见的那一行,它会显示图像并且没有问题。
//Unzip a zip file protected and overwrite if needed
using (ZipFile zip = ZipFile.Read(Directory.GetCurrentDirectory().ToString() + "\\Pictures" + "\\image1.zip"))
{
zip.Password = "1234";
zip.ExtractAll(Directory.GetCurrentDirectory().ToString() + "\\Pictures\\", Ionic.Zip.ExtractExistingFileAction.DoNotOverwrite);
}
pictureBox1.ImageLocation = Directory.GetCurrentDirectory().ToString() + "\\Pictures" + "\\image1.jpg";
File.Delete(Directory.GetCurrentDirectory().ToString() + "\\Pictures" + "\\image1.jpg");
答案 0 :(得分:1)
var imagePath = Directory.GetCurrentDirectory().ToString() + "\\Pictures" + "\\image1.jpg;
pictureBox1.LoadCompleted += (s, e) => File.Delete(imagePath);
pictureBox1.ImageLocation = imagePath;