从WPF中的图像中读取元数据

Row*_*haw 4 .net wpf metadata image

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

显然可以这样做,因为Windows资源管理器显示它,但这是通过.net API公开的,或者你认为它只是调用本机COM接口

Ken*_*art 9

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

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;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 对于通过谷歌来到这里的其他人,肯特上面的例子中的`_orientationQuery`是"System.Photo.Orientation". (3认同)