问题描述
我一直在四处寻找的元数据读取一个体面的方式(具体拍摄日期)的JPEG文件在C#中,和我来了有点短。现有的信息,据我所看到的,显示如下所示的代码;
I've been looking around for a decent way of reading metadata (specifically, the date taken) from JPEG files in C#, and am coming up a little short. Existing information, as far as I can see, shows code like the following;
BitmapMetadata bmd = (BitmapMetadata)frame.Metadata;
string a1 = (string)bmd.GetQuery("/app1/ifd/exif:{uint=36867}");
但在我的无知,我不知道会返回一个元数据GetQuery位(),或者什么通过它。
But in my ignorance I have no idea what bit of metadata GetQuery() will return, or what to pass it.
我要首先尝试读取XMP,回落至EXIF如果XMP不存在。有没有这样做?
I want to attempt reading XMP first, falling back to EXIF if XMP does not exist. Is there a simple way of doing this?
感谢。
推荐答案
下面似乎很好地工作,但如果有一些不好的话,我会很感激任何意见。
The following seems to work nicely, but if there's something bad about it, I'd appreciate any comments.
public string GetDate(FileInfo f)
{
using(FileStream fs = new FileStream(f.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
BitmapSource img = BitmapFrame.Create(fs);
BitmapMetadata md = (BitmapMetadata)img.Metadata;
string date = md.DateTaken;
Console.WriteLine(date);
return date;
}
}
这篇关于从读取JPEG,XMP和EXIF数据的元数据在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!