重新加载在WPF图像 [英] Reloading an image in wpf

查看:593
本文介绍了重新加载在WPF图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重新加载图像(System.Windows.Controls.Image)我在WPF显示。我设置的来源是这样的:

I'm trying to reload an image (System.Windows.Controls.Image) I display in WPF. I set the source like this:

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

我做了一个按钮,它会迫使这一形象的重新加载(它更改了磁盘上每一秒)。

I made a button, which should force a reload of this image (it changes on disk every second).

我曾尝试复位源,但是,这并不做任何事情。但是,如果我更改源,以不同的图像,这种不同的图像并得到加载。好像事情是beeing缓存?

I have tried resetting the Source, but that doesn't do anything. However if I change the Source to a different image, this different image does get loaded. It seems like something is beeing cached?

感谢您的帮助。

推荐答案

研究发现,对我的作品的答案:

Found an answer that works for me:

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;

这篇关于重新加载在WPF图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆