gpt4 book ai didi

wpf - 在运行时删除图像

转载 作者:行者123 更新时间:2023-12-04 06:39:04 26 4
gpt4 key购买 nike

我正在尝试使用以下方法删除图像:
(文件路径100%正确)

if(File.Exists(filePath))
File.Delete(filePath);

我得到以下异常:

An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll

Additional information: The process cannot access the file 'C:\visual_programming\yad2\yad2\bin\Debug\images\1.jpg' because it is being used by another process.

最佳答案

这是直接绑定(bind)到 Image 控件的 ImageSource 的图像的常见问题。您应该通过 BitmapImage 创建 ImageSource 并将 BitmapImage.CacheOption 属性设置为 BitmapCacheOption.OnLoad:

BitmapImage bi = new BitmapImage();

// Begin initialization.
bi.BeginInit();

// Set properties.
bi.CacheOption = BitmapCacheOption.OnLoad;
//
bi.EndInit();

More Details about BitmapImage.CacheOption on MSDN

关于wpf - 在运行时删除图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4498769/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com