删除在图片框中打开的图片:
private void button1_Click_1(object sender, EventArgs e)
{
lblimgname.Text = "Right Thumb 1";
string savepath = @"C:/BrainScript/" + clientname + "/";
FileStream fs = new FileStream(savepath + clientname + "_" + lblimgname.Text + ".jpg", FileMode.Open, FileAccess.Read);
Image img = Image.FromStream(fs);
fs.Close();
picRightthumb1.Image = img.Clone() as Image;
img.Dispose();
File.Delete(savepath + clientname + "_" + lblimgname.Text + ".jpg");
}
private Image GetCopyImage(string path)
{
using (Image im = Image.FromFile(path))
{
Bitmap bm = new Bitmap(im);
return bm;
}
}
我已经编写了上面的代码来删除在图片框中打开的图像,但是我收到错误“该过程被另一个进程使用”请帮我解决这个问题。
答案 0 :(得分:0)
我使用了以下代码并且工作正常:
private void button1_Click(object sender, EventArgs e)
{
FileStream file = new FileStream("1.jpg", FileMode.Open);
pictureBox1.Image = Image.FromStream(file);
file.Close();
File.Delete("1.jpg");
}