【发布时间】:2015-05-11 09:29:52
【问题描述】:
我有一个从视频文件中获取快照图像的 WPF 应用程序。用户可以定义从中获取图像的时间戳。然后将图像保存到磁盘上的一个临时位置,然后渲染到一个<image> 元素中。
然后用户应该能够选择不同的时间戳,然后覆盖磁盘上的临时文件 - 这应该会显示在 <image> 元素中。
使用Image.Source = null;,我可以清除 <image> 元素中的图像文件,因此它会显示一个空白区域。但是,如果源图像文件随后被新图像(同名)覆盖并加载到<image> 元素中,它仍会显示旧图像。
我正在使用以下逻辑:
// Overwrite temporary file file here
// Clear out the reference to the temporary image
Image_Preview.Source = null;
// Load in new image (same source file name)
Image = new BitmapImage();
Image.BeginInit();
Image.CacheOption = BitmapCacheOption.OnLoad;
Image.UriSource = new Uri(file);
Image.EndInit();
Image_Preview.Source = Image;
<image> 元素中显示的图像不会改变,即使原始文件已被完全替换。这里是否存在我不知道的图像缓存问题?
【问题讨论】: