本文介绍了从WPF中的图像中读取元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我知道WPF允许你使用需要WIC编解码器查看的图像(为了争论,比如数码相机RAW文件);但是我只能看到它可以让你本地显示图像,但我无法看到获取元数据(例如,曝光时间)。



解决方案

查看我的项目。特别是类,它读取元数据以确定图像的方向:

 使用(FileStream fileStream = new FileStream(path,FileMode.Open,FileAccess.Read))
{
BitmapFrame bitmapFrame = BitmapFrame.Create(fileStream,BitmapCreateOptions.DelayCreation,BitmapCacheOption.None);
BitmapMetadata bitmapMetadata = bitmapFrame.Metadata as BitmapMetadata;

if((bitmapMetadata!= null)&&(bitmapMetadata.ContainsQuery(_orientationQuery)))
{
object o = bitmapMetadata.GetQuery(_orientationQuery);

if(o!= null)
{
//有关方向值的详细信息,请参阅http://www.impulseadventure.com/photo/exif-orientation.html
开关((ushort)o)
{
案例6:
返回90D;
案例3:
返回180D;
案例8:
返回270D;
}
}
}
}


I'm aware that WPF allows you to use images that require WIC codecs to view (for the sake of argument, say a digital camera RAW file); however I can only see that it lets you show the image natively, but I can't see anyway of getting at the meta-data (for example, the exposure time).

It obviously can be done, as Windows Explorer shows it, but is this exposed through the .net API or do you reckon that it is just down to calling the native COM interfaces

解决方案

Check out my Intuipic project. In particular, the BitmapOrientationConverter class, which reads metadata to determine the image's orientation:

using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
    BitmapFrame bitmapFrame = BitmapFrame.Create(fileStream, BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);
    BitmapMetadata bitmapMetadata = bitmapFrame.Metadata as BitmapMetadata;

    if ((bitmapMetadata != null) && (bitmapMetadata.ContainsQuery(_orientationQuery)))
    {
        object o = bitmapMetadata.GetQuery(_orientationQuery);

        if (o != null)
        {
            //refer to http://www.impulseadventure.com/photo/exif-orientation.html for details on orientation values
            switch ((ushort) o)
            {
                case 6:
                    return 90D;
                case 3:
                    return 180D;
                case 8:
                    return 270D;
            }
        }
    }
}

这篇关于从WPF中的图像中读取元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:54