问题描述
在Windows窗体应用程序中,某些图像文件被分配给PictureBox控件。我想删除那些图像文件。第一种方法[1]带有"Image.FromFile"。给出了"另一个进程正在使用该图像文件"的错误消息,尽管"Image.Dispose()"也是如此。执行
。第二种方法[2]使用"Image.FromStream";如果"fs.Close()",则为PictureBoxes和Buttons的结果(X)图像。是的。如果没有"fs.Close()",它会给出"另一个进程正在使用..."的相同错误消息。如何正确显示图像
并删除这些图像文件?
In a Windows form application, some image files are assigned to PictureBox controls. I am trying to delete those image files. The first approach [1] with "Image.FromFile" gives an error message of "Another process is using this image file", although "Image.Dispose()" is executed. The second approach [2] using "Image.FromStream" results (X) images for PictureBoxes and Buttons, if "fs.Close()" is inclided. Without "fs.Close()", it gives the same error message of "Another process is using...". How can I display images properly and delete those images files ?
谢谢
[1]
pictureBoxSelected.Image = Image.FromFile(@actualImage);
。
。
。
pictureBoxSelected.Image.Dispose();
$
pictureBoxSelected.Image = Image.FromFile(@tempImage);
                                        
if(System.IO.File.Exists(actualImage)== true)
{
; System.IO.File.Delete(actualImage);
}
pictureBoxSelected.Image = Image.FromFile(@actualImage);
.
.
.
pictureBoxSelected.Image.Dispose();
pictureBoxSelected.Image = Image.FromFile(@tempImage);
if (System.IO.File.Exists(actualImage) == true)
{
System.IO.File.Delete(actualImage);
}
[2]
FileStream fs = new FileStream (fileName,FileMode.Open,FileAccess.Read);
$
pictureBox.Image = System.Drawing.Image.FromStream(fs);
fs.Close();
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
pictureBox.Image = System.Drawing.Image.FromStream(fs);
fs.Close();
推荐答案
您好,
如果您使用picturebox的ImageLocation属性,则可以使用相同的属性设置图片,您可以获得图片路径...
If you use ImageLocation property of picturebox you can then set picture also using same property you can get Picture path...
pictureBox1.ImageLocation = @" c:\ pic。 jpg";
pictureBox1.ImageLocation = @"c:\pic.jpg";
干杯,
这篇关于如何删除分配给PictureBox xontrol的图像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!