【发布时间】:2009-05-01 14:06:16
【问题描述】:
我在尝试删除图像文件时遇到问题。 我总是收到一条错误消息:IOExeption 未处理。访问被拒绝,因为该文件正被另一个进程使用。
我不知道这可能是什么过程以及如何解决它。
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
专辑专辑 = GetAlbum(comboBox1.SelectedIndex);
照片照片 = GetPhoto(comboBox1.SelectedIndex, comboBox3.SelectedIndex);
txtPhotoPath.Text = Directory.GetCurrentDirectory() + "\\" + photo.SPath;
lblExtention.Text = 照片.SExtention;
txtPhotoTitle.Text = 照片.STitle;
pctrbFoto.Image = Image.FromFile(foto.SPath).GetThumbnailImage(GetWitdth(photo.SPath, GetHeight(photo.SPath, 150)), GetfHeight(photo.SPath, 150), null, new IntPtr());
}
私人无效btnChangePhoto_Click(对象发送者,EventArgs e)
{
专辑专辑 = GetAlbum(comboBox1.SelectedIndex);
照片照片 = GetPhoto(comboBox1.SelectedIndex, comboBox3.SelectedIndex);
File.Delete("相册\\图片\\" + photo.STitle + foto.SExtention);
photo.SExtention = lblExtention.Text;
photo.STitle = txtPhotoTitel.Text;
Photo.SPath = txtPath.Text;
File.Copy(photo.SPath, "Albums\\Images\\" + photo.STitle + photo.SExtention);
}
谢谢, 文森特
感谢大家的帮助。
我用过这个,现在效果很好
您的进程是使用文件的进程,您需要将 image 设置为 null 使用类似这样的东西:
var img = Image.FromFile(foto.SPath).GetThumbnailImage(GetWitdth(photo.SPath, GetHeight(photo.SPath, 150)), GetfHeight(photo.SPath, 150), null, new IntPtr());
pctrbFoto.Image = img;
img = null;
GC.Collect();
【问题讨论】:
标签: c# error-handling