我有以下代码:
imgScreenshot.Source = new BitmapImage(new Uri(ShellFolder.DocumentsFolder() + System.IO.Path.DirectorySeparatorChar + screenshot.Filename));
File.Delete(ShellFolder.DocumentsFolder() + System.IO.Path.DirectorySeparatorChar + screenshot.Filename);
我收到错误:
我考虑过处理BitmapImage,但是这个类没有实现这个接口。如何正确编写此代码?{"进程无法访问文件' C:\ Users \ rover \ Documents \ MagicScreenshot \ vEhWg3Ra20M.jpg'因为它正被另一个进程使用。"}
答案 0 :(得分:2)
尝试:
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(ShellFolder.DocumentsFolder() + System.IO.Path.DirectorySeparatorChar + screenshot.Filename);
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.EndInit();
imgScreenshot.Source = bi;
File.Delete(ShellFolder.DocumentsFolder() + System.IO.Path.DirectorySeparatorChar + screenshot.Filename);