创建BitmapImage会抛出丢失的键异常 [英] Creating BitmapImage throws missing key exception

查看:187
本文介绍了创建BitmapImage会抛出丢失的键异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,显示带有标题和注释的图像。
当我加载现有的图像时,我使用这个代码:

I have a view that displays an image with it's title and comment alongside it. When I load up existing images I utilize this code:

        this.ArtifactIdentity = image.ArtifactIdentity;
        this.Comment = image.Comment;
        this.Name = image.Name;
        this.MediaIdentity = image.MediaIdentity;
        this.ImageArray = image.Image;
        Image = new BitmapImage();
        Image.BeginInit();
        Image.CacheOption = BitmapCacheOption.None;
        Image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
        Image.StreamSource = new MemoryStream(this.ImageArray);
        Image.EndInit();



当我执行EndInit()时抛出异常缺少参数键。堆栈跟踪显示以下内容:System.Collections.Hashtable.ContainsKey(Object key)
在System.Collections中的堆栈跟踪显示:

When I execute the EndInit() it throw the exception missing parameter key. The stack trace shows this:

  at System.Collections.Hashtable.ContainsKey(Object key)
  at System.Collections.Hashtable.Contains(Object key)
  at System.Windows.Media.Imaging.ImagingCache.RemoveFromCache(Uri uri, Hashtable table)
  at System.Windows.Media.Imaging.BitmapImage.FinalizeCreation()
  at System.Windows.Media.Imaging.BitmapImage.EndInit()

我为什么我得到这个异常,当我使用代码我见过许多其他使用成功,但我得到这个异常?

So can anyone tell me why I am getting this exception when I am using code I've seen many others use with success and yet I get this exception??? I'm at a loss!

推荐答案

这是由WPF中的一个错误,在 BitmapImage中引起的。 FinalizeCreation()

This is caused by a bug in WPF, in BitmapImage.FinalizeCreation():

if ((CreateOptions & BitmapCreateOptions.IgnoreImageCache) != 0)
{
    ImagingCache.RemoveFromImageCache(uri); 
}

如果指定 IgnoreImageCache ,但不能从URI加载,它会破坏。

If you specify IgnoreImageCache, but don't load from a URI, it breaks.

只是摆脱那个标志;它只适用于从网址载入时。

Just get rid of that flag; it only applies when loading from URLs.

这篇关于创建BitmapImage会抛出丢失的键异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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