在 C# 中从 JPEG、XMP 或 EXIF 读取数据元数据
我一直在寻找一种在 C# 中从 JPEG 文件中读取元数据(特别是拍摄日期)的好方法,但我的发现有点短。据我所知,现有信息显示的代码如下;
BitmapMetadata bmd = (BitmapMetadata)frame.Metadata;
string a1 = (string)bmd.GetQuery("/app1/ifd/exif:{uint=36867}");
但由于我的无知,我不知道 GetQuery() 将返回哪些元数据,或者传递什么。
我想首先尝试读取 XMP,如果 XMP 不存在,则返回到 EXIF。有没有一种简单的方法可以做到这一点?
谢谢。
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}");
But in my ignorance I have no idea what bit of metadata GetQuery() will return, or what to pass it.
I want to attempt reading XMP first, falling back to EXIF if XMP does not exist. Is there a simple way of doing this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
以下似乎工作得很好,但如果有什么不好的地方,我会很感激任何评论。
The following seems to work nicely, but if there's something bad about it, I'd appreciate any comments.
我最近将我的长期开源 Java 库移植到了 .NET,它支持 XMP、Exif、ICC、JFIF 以及跨一系列图像格式的更多类型的元数据。它一定会实现你所追求的。
https://github.com/drewnoakes/metadata-extractor-dotnet
该库还通过 Adobe XmpCore Java 库的 C# 端口支持 XMP 数据。
https://github.com/drewnoakes/xmp-core-dotnet
I've ported my long-time open-source Java library to .NET recently, and it supports XMP, Exif, ICC, JFIF and many more types of metadata across a range of image formats. It will definitely achieve what you're after.
https://github.com/drewnoakes/metadata-extractor-dotnet
This library also supports XMP data, via a C# port of Adobe's XmpCore library for Java.
https://github.com/drewnoakes/xmp-core-dotnet
如果您在使用 XMP jn jpeg 时遇到困难,那么这很有效。这可不是无缘无故的残酷!
If you're struggling with XMP jn jpeg, this works. It's not called brutal for nothing!
我认为您正在做的事情是一个很好的解决方案,因为 System.DateTaken 处理程序会自动应用 照片元数据策略,返回到其他命名空间以查找值是否存在。
I think what you are doing is a good solution because the System.DateTaken handler automatically apply Photo metadata policies of falling back to other namespaces to find if a value exist.
如果您尝试访问这些属性:
您可以执行以下操作:
代码示例:
控制台将显示代表感兴趣值的字符串。我不确定为什么包含个位数月份和/或日期值的日期会显示一个?对于 0 数字。这些可以轻松替换,然后可以解析日期。以下是 Properties\Details 选项卡中显示的一些有趣的输出:
据我所知,有多达 320 种不同的标记类型。
If you are trying to access these properties:
You can do the following:
Code Sample:
The console will display strings representing the values of interest. I'm not sure why, by dates containing single digit month and/or day values will display a ? for the 0 digit. These can easily be replaced and then the date can be parsed. Here is the output for some of the interesting ones displayed in the Properties\Details tab:
As far as I am aware, there are as many as 320 different tag types.
我的 公司 开发了 .NET 工具包,包括 XMP 和 EXIF 解析器。
典型的过程是这样的:
对于 EXIF,你会这样做:
显然,对于 JPEG,frameIndex 将为 0。
My company makes a .NET toolkit that includes XMP and EXIF parsers.
The typical process is something like this:
for EXIF you would do this:
obviously, frameIndex would be 0 for JPEG.