我知道WPF允许您使用需要WIC编解码器才能查看的图像(例如数码相机RAW文件)。但是,我只能看到它可以原生地显示图像,但我无法找到任何获取元数据的方法(例如曝光时间)。
显然可以做到,因为Windows资源管理器可以显示它,但是它是通过.NET API公开还是只需调用本机COM接口?
显然可以做到,因为Windows资源管理器可以显示它,但是它是通过.NET API公开还是只需调用本机COM接口?
欢迎查看我的Intuipic项目,特别是BitmapOrientationConverter类,该类通过读取元数据来确定图像的方向:
private const string _orientationQuery = "System.Photo.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;
}
}
}
}
// Read all metadata from the image
var directories = ImageMetadataReader.ReadMetadata(stream);
// Find the so-called Exif "SubIFD" (which may be null)
var subIfdDirectory = directories.OfType<ExifSubIfdDirectory>().FirstOrDefault();
// Read the orientation
var orientation = subIfdDirectory?.GetInt(ExifDirectoryBase.TagOrientation);
switch (orientation)
{
case 6:
return 90D;
case 3:
return 180D;
case 8:
return 270D;
}
var directories = JpegMetadataReader.ReadMetadata(stream, new[] { new ExifReader() });
metadata-extractor 库可以通过 NuGet 和 GitHub 上的代码 获得。
自从 2002 年启动以来,许多贡献者对该项目做出了贡献,特此致谢。
"ExifDirectoryBase.TagOrientation
吗? - Wouter
_orientationQuery
是"System.Photo.Orientation"
。 - Isak Savo