添加自定义命名空间中的元数据(BitmapMetadata) [英] Adding custom namespace to metadata (BitmapMetadata)
问题描述
下面是一个简单的问题:如何正确添加自定义命名空间用来XMP BitmapMetadata code>
Here's a quick question: how to correctly add a custom namespace to XMP using BitmapMetadata
?
比方说,我想命名空间看起来像这样:的xmlns:myNameSpace对象=HTTP://测试
Let's say I want the namespace to look like this: xmlns:MyNamespace="http://test"
有没有明确的方法如何添加命名空间中的 BitmapMetadata code>,所以我尝试这样的:
There's no clear way how to add the namespace in the BitmapMetadata
, so I tried this:
//I retrieve the image frame (Frame[0]), then:
var metadata = (BitmapMetadata) frame.Metadata.Clone();
//Covering all bases
metadata.SetQuery("/app1/ifd/PaddingSchema:Padding", 4096);
metadata.SetQuery("/app1/ifd/exif/PaddingSchema:Padding", 4096);
metadata.SetQuery("/xmp/PaddingSchema:Padding", 4096);
而现在的主查询,我试图去了明显的方式:
And now the main query, I tried going the 'obvious way':
metadata.SetQuery("/xmp/MyNamespace:MyTag", "AwesomeTagValue");
果然,当我保存图片,打开并运行
And sure enough, if I save the image, open it and run
var value = (string) metadata.GetQuery("/xmp/MyNamespace:MyTag");
它返回正确的值 - AwesomeTagValue
it returns the correct value - AwesomeTagValue.
下面是虽然,标签写入与畸形的命名空间中的文件的问题。 我偷看到文件中,这里的剥离XML / RDF观点:
Here's the problem though, the tags are written to the file with malformed namespace. I peeked into the file and here's the stripped XML/RDF view:
<rdf:Description rdf:about="" xmlns:prefix0="MyNamespace"> ... </rdf:Description>
因此,所有的标签是prefixed与 prefix0
,我想它是
<rdf:Description rdf:about="" xmlns:MyNamespace="http://test"> ... </rdf:Description>
任何想法如何做到这一点,或者如果它甚至有可能与 BitmapMetadata code>?
推荐答案
您可以使用 BitmapMetadata code>达到最佳的:
The best you can achieve with BitmapMetadata
:
<rdf:Description xmlns:prefix0="http://test">...</rdf:Description>
下面是元数据查询:
metadata.SetQuery("/xmp/{wstr=http://test}:MyTag", "AwesomeTagValue");
据文件:
如果没有友好模式preFIX为一个特定的模式,对 例如,如果图像包含使用自定义的第三方XMP元数据 架构,元数据查询应该使用完整的架构URL。
If there is no friendly schema prefix for a particular schema, for example if an image contains XMP metadata using a custom third party schema, the metadata query should use the full schema URL.
所以,如果你是不是满意的结果,你可以:
So if you are not satisfied with the result you could:
- 打开图像文件,并替换所有
prefix0
与myNameSpace对象
- 使用第三方库修改元数据
这篇关于添加自定义命名空间中的元数据(BitmapMetadata)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!