我的自定义图片框包含一个滚动查看器和一个图像。类型为string的依赖属性image用于设置图像。
public static DependencyProperty ImageProperty = DependencyProperty.Register(
"Image", typeof(string), typeof(CustomPictureBox), new FrameworkPropertyMetadata("", new PropertyChangedCallback(OnImageChanged)));
private static void OnImageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CustomPictureBox cpb = (CustomPictureBox)d;
if (e.Property == ImageProperty)
{
string newvalue = e.NewValue as string;
if (!(string.IsNullOrEmpty(newvalue)))
{
var bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = new Uri(newvalue);
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.EndInit();
cpb.imgPicture.Source = bmp;
}
else
cpb.imgPicture.Source = null;
}
}通过帧采集器获取图像,并将其存储到名为"camera_image.tif“的给定位置。Image属性设置为此文件名。当我开始新的图像采集时,我通过绑定将image属性设置为null,并且图片框更新为不显示任何图像。当图像采集完成后,我再次将其设置为"camera_image.tif“。问题是新的图像永远不会出现。相反,它始终是显示在图片框中的第一个获取的图像。当我检查图像文件时,它包含了新的内容。
如何让图片框刷新图像?
致以敬意,
塔比娜
发布于 2012-05-11 18:16:02
我在这里找到了答案:
Reloading an image in wpf和这里。WPF Image.Source caching too aggressively
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.CreateOptions = BitmapCreateOptions.IgnoreImageCache;就是我要找的解决方案!
https://stackoverflow.com/questions/10518986
复制相似问题