我正在尝试创建一个用户资料编辑窗口,在这个窗口中有一个图像控件。
当我选择一个图像文件时,它会显示在这个图像控件中,并将此文件复制到我的图像文件夹中,第一次没问题,但第二次出现了错误
"The process cannot access the file 'C:\1.jpg' because it is being used by another process."
我认为这是因为我的图像控件正在使用此文件,所以我不知道该怎么办。
private void Select_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog od = new OpenFileDialog();
if (od.ShowDialog() == true)
{
string imageLocal = @"C:/1.jpg";
File.Copy(od.FileName, imageLocal, true);
image1.Source = new BitmapImage(new Uri(imageLocal));
}
}