10

我正在尝试重新加载我在 WPF 中显示的图像 (System.Windows.Controls.Image)。我这样设置源:

ScreenAtco01Image.Source = new BitmapImage(new Uri(@"Y:/screenshots/naratco08-0-0-screenshot.png", UriKind.RelativeOrAbsolute));

我做了一个按钮,它应该强制重新加载这个图像(它每秒都会在磁盘上改变)。

我曾尝试重置源,但这无济于事。但是,如果我将 Source 更改为不同的图像,则会加载这个不同的图像。好像有东西被缓存了?

谢谢你的帮助。

4

1 回答 1

26

找到了一个适合我的答案:

BitmapImage _image = new BitmapImage();
_image.BeginInit();
_image.CacheOption = BitmapCacheOption.None;
_image.UriCachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
_image.CacheOption = BitmapCacheOption.OnLoad;
_image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
_image.UriSource = new Uri(@"Y:/screenshots/naratco08-0-0-screenshot.png", UriKind.RelativeOrAbsolute);
_image.EndInit();
ScreenAtco01Image.Source = _image;
于 2009-09-29T10:08:13.683 回答