当我尝试删除图像时,出现此错误,我试图处理图片框,但这似乎不起作用。
System.IO.IOException:'进程无法访问文件 'C:\ Users ******* \ Documents \ Visual Studio 2019 \ Project **************** \ dbo \ DBImages \ Bolgheri Sassicaia.jpg' 因为它正在被另一个进程使用。'
我从此文件夹加载的图像,我想将其删除,然后添加另一张具有相同名称的图片。 我几乎想更新图像。
这是我将图像加载到图片框的地方
if (imagepathtext.TextLength > 0)
{
image1 = Image.FromFile(imagepathtext.Text);
drinkImageView.Image = image1;
}
这是我尝试替换图像的地方。
private void UpdatebtnClick(object sender,EventArgs e)
{
if (imagepath.TextLength > 9)
{
DialogResult result = MessageBox.Show("Are you also trying to
update image?","Confirmation",MessageBoxButtons.Yesno);
if (result == DialogResult.Yes)
{
image1.Dispose();
System.IO.File.Delete(imagepathtext.Text);
}
}
}