使用BitmapFrame元数据不锁定文件 [英] Using BitmapFrame for metadata without locking the file

查看:341
本文介绍了使用BitmapFrame元数据不锁定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现让图像元数据在WPF中常见的方式是创建一个 BitmapFrame 对象,并检查元数据属性就可以了。不过,我似乎无法创建一个 BitmapFrame 对象,满足这两个要求:

I've found the common way to get image metadata in WPF is to create a BitmapFrame object and inspect the Metadata property on it. However I can't seem to create a BitmapFrame object that fulfills these two requirements:

  1. 在不锁定文件
  2. 在给定的某些文件时,不会引发怪异,无证例外

使用这些线,似乎创造了的BitmapImage 可靠:

Using these lines seems to create the BitmapImage reliably:

BitmapFrame.Create(new Uri(imageName));
BitmapFrame.Create(new Uri(imageName), BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);

不过,他们离开锁定一个不确定的时间的文件。没有任何关于Dispose方法 BitmapFrame 据我可以告诉。

这使得此文件被锁定:

BitmapFrame.Create(new Uri(imageName), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);

不过在Vista上,它抛出的ArgumentException InvalidOperationException异常上的某些文件和Win7上的IT抛出 FileFormatException IOException异常秒。这让我觉得,缓存 BitmapFrame 是不支持/未经测试。

However on Vista it throws ArgumentExceptions and InvalidOperationExceptions on certain files and on Win7 it throws FileFormatExceptions and IOExceptions. This makes me think that caching the BitmapFrame is unsupported/untested.

您可以得到在WPF图像元数据不留在文件上的锁的时间是不确定的长度?

Can you get metadata from an image in WPF without leaving a lock on the file for an indeterminate length of time?

推荐答案

你有没有尝试过使用转换器的方法吗?例如,我的 Intuipic 应用程序做到这一点。请参见 BitmapFrameConverter 为无锁上装载的详细信息,并 BitmapOrientationConverter 获取的元数据。

Have you tried using a converter approach? For example, my Intuipic application does this. See BitmapFrameConverter for details on loading without locking, and BitmapOrientationConverter for getting at metadata.

这篇关于使用BitmapFrame元数据不锁定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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