简体   繁体   English

在c#中使用元数据提取器获取自定义XMP元数据

[英]Getting custom XMP metadata using metadata-extractor in c#

I am writing some XMP metadata using a photoshop .jsx script using : 我正在使用photoshop .jsx脚本编写一些XMP元数据:

var xmp = new XMPMeta( activeDocument.xmpMetadata.rawData); XMPMeta.registerNamespace(nameSpace, nsPrefix);

and then adding some data to this new namespace. 然后将一些数据添加到此新命名空间。 I am able to view it in Photoshop by checking under File -> FileInfo . 我可以通过在File -> FileInfo下检查来在Photoshop中查看它。 My question is how can I access this data using the metadata extractor library in my c# project ? 我的问题是如何使用我的c#项目中的元数据提取器库来访问这些数据? When I use the following code I do not see the new metadata I added inside any of the directories: 当我使用以下代码时,我没有看到我在任何目录中添加的新元数据:

FileStream OriginalFile = new FileStream("C:\\\\Users\\\\av\\\\Desktop\\\\test.tif", FileMode.Open, FileAccess.Read, FileShare.Read); IEnumerable<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(OriginalFile);

Edit: I am able to loop through all the properties but when I try to do 编辑:我能够遍历所有属性但是当我尝试时

var xmpDirectory = ImageMetadataReader.ReadMetadata("path/test.tif").OfType<XmpDirectory>().FirstOrDefault(); xmpDirectory.XmpMeta.GetProperty("http://ns.adobe.com/xap/1.0/mm/xmpMM:DerivedForm/", "stRef:documentID")

I get an exception. 我得到一个例外。 The property is present when I look at it through Photoshop. 当我通过Photoshop查看它时,该属性存在。

xmp data in photoshop 在photoshop中的xmp数据

XMP data is stored in the XmpDirectory . XMP数据存储在XmpDirectory Access it via: 访问它:

var xmpDirectory = ImageMetadataReader.ReadMetadata("path\test.tif")
    .OfType<XmpDirectory>().FirstOrDefault();

Note however that XMP data in metadata-extractor does not follow the standard tag/value format of other directories. 但请注意,元数据提取器中的XMP数据不遵循其他目录的标准标记/值格式。 Instead, you should access the XmpMeta property of the directory in order to inspect that data. 相反,您应该访问目录的XmpMeta属性以检查该数据。

You can then write code resembling: 然后你可以编写类似的代码:

foreach (var property in xmpDirectory.XmpMeta.Properties)
    Console.WriteLine($"Path={property.Path} Namespace={property.Namespace} " +
                       "Value={property.Value}");

Some more discussion here and more information about the XMP library here . 一些更多的讨论在这里和有关XMP库的详细信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM