图片不自定义图片框刷新 [英] Image does not refresh in custom picture box

查看:164
本文介绍了图片不自定义图片框刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的自定义图片框中包含的ScrollViewer和图像。
string类型的dependecy财产图像用于设置图像。

My custom picture box contains a scrollviewer and an image. A dependecy property Image of type string is used to set the 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。图像属性设置为这个文件名。
当我开始一个新的图像采集,我通过结合空集图像属性和图片框更新,以显示没有图像。
当图像采集完成后,我再次设置到camera_image.tif。现在的问题是,新的形象一直没有出现。相反,它始终是在图片框内显示第一获取的图像。当我检查图像文件,它包含了新的内容。

An image is acquired via frame grabber and stored to a given location with name "camera_image.tif". The Image property is set to this filename. When I start a new image acquisition, I set the Image property via binding to null and the picture box updates to show no image. When the image acquisition is done, I set it to the "camera_image.tif" again. The problem is that the new image never shows up. Instead it is always the first acquired image that is displayed within the picture box. When I check the image file, it contains the new content.

怎么能拿图片框来刷新图像?

How could I get the picture box to refresh the image?

问候,

tabina

推荐答案

我在这里找到了答案:

重​​新加载在WPF 图像
和这里。
WPF Image.Source缓存过于激进

bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.CreateOptions = BitmapCreateOptions.IgnoreImageCache;

是我一直在寻找解决方案!

is the solution I was looking for!

这篇关于图片不自定义图片框刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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