C# 在xmpdc:Subject字段中存储数组
我试图复制Adobe Lightroom如何在图像(JPEG)结构中存储“关键字” 到目前为止,我发现关键字存储在字段中的元数据中 /xmp/dc:主题 Light room将每个标记存储为xml结构,格式如下:C# 在xmpdc:Subject字段中存储数组,c#,xmp,C#,Xmp,我试图复制Adobe Lightroom如何在图像(JPEG)结构中存储“关键字” 到目前为止,我发现关键字存储在字段中的元数据中 /xmp/dc:主题 Light room将每个标记存储为xml结构,格式如下: <dc:subject> <rdf:Bag> <rdf:li>Bianca</rdf:li> <rdf:li>KEYWORDS -LR</rdf:li> &l
<dc:subject>
<rdf:Bag>
<rdf:li>Bianca</rdf:li>
<rdf:li>KEYWORDS -LR</rdf:li>
<rdf:li>Laura</rdf:li>
<rdf:li>Lyndel</rdf:li>
<rdf:li>T-ALL</rdf:li>
</rdf:Bag>
</dc:subject>
<dc:subject>Bianca; KEYWORDS -LR; Laura; Lyndel; T-ALL</dc:subject>
编辑:
在该链接中,显示了应在以下查询中进行写入:
/xmp/dc:subject
但是它是什么呢
Edit2:
结果表明,写入“位置”如下所示:
/xmp/dc:subject/{ulong=0}
/xmp/dc:subject/{ulong=1}
//读取图像流
使用(var originalFile=File.Open(路径,FileMode.Open,FileAccess.Read,FileShare.None))
{
//创建位图解码器
decoder=BitmapDecoder.Create(原始文件、createOptions、BitmapCacheOption.None);
//第一帧包含图像元数据
var bitmapFrame=decoder.Frames[0];
if(bitmapFrame!=null&&bitmapFrame.Metadata!=null)
{
//为了能够修改元数据,首先我们需要克隆它
BitmapMetadata metadata=bitmapFrame.metadata.Clone()作为BitmapMetadata;
//删除XP主题字段
metadata.RemoveQuery(“System.Subject”);
//删除XP关键字字段
metadata.RemoveQuery(“System.Keywords”);
//写标签(照明室钥匙用语)
var关键字=“K1;K2;K3”;
var keywordArray=keywords.Split(新[]{;“},StringSplitOptions.RemoveEmptyEntries);
//写入XMP部分
SetQuery(“/xmp/dc:Subject”,新的位图元数据(“xmpbag”);
for(var i=0;i
// Read the image stream
using (var originalFile = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None))
{
// Create the bitmap decoder
decoder = BitmapDecoder.Create(originalFile, createOptions, BitmapCacheOption.None);
// The the first frame contains the image metadata
var bitmapFrame = decoder.Frames[0];
if (bitmapFrame != null && bitmapFrame.Metadata != null)
{
// To be able to modify the metadata, first we need to clone it
BitmapMetadata metadata = bitmapFrame.Metadata.Clone() as BitmapMetadata;
// Remove the XP Subject field
metadata.RemoveQuery("System.Subject");
// Remove the XP keyword field
metadata.RemoveQuery("System.Keywords");
// Write Tags (Lightroom keywording)
string keywords = "K1; K2; K3";
metadata.SetQuery("/xmp/dc:Subject", keywords);
// Create a bitmap encoder
var encoder = CreateBitmapEncoder(imageFormat);
// Create new frame with the updated metadata
// Keep everything the same except the updated metadata
encoder.Frames.Add(BitmapFrame.Create(
bitmapFrame, bitmapFrame.Thumbnail, metadata, bitmapFrame.ColorContexts));
// Attemp to save the update image
using (Stream outputFile = File.Open(path + tempSufix, FileMode.Create, FileAccess.ReadWrite))
{
encoder.Save(outputFile);
}
}
}
// Read the image stream
using (var originalFile = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None))
{
// Create the bitmap decoder
decoder = BitmapDecoder.Create(originalFile, createOptions, BitmapCacheOption.None);
// The the first frame contains the image metadata
var bitmapFrame = decoder.Frames[0];
if (bitmapFrame != null && bitmapFrame.Metadata != null)
{
// To be able to modify the metadata, first we need to clone it
BitmapMetadata metadata = bitmapFrame.Metadata.Clone() as BitmapMetadata;
// Remove the XP Subject field
metadata.RemoveQuery("System.Subject");
// Remove the XP keyword field
metadata.RemoveQuery("System.Keywords");
// Write Tags (Lightroom keywording)
var keywords = "K1; K2; K3";
var keywordArray = keywords.Split(new[] { "; " }, StringSplitOptions.RemoveEmptyEntries);
// Write in the XMP section
metadata.SetQuery("/xmp/dc:Subject", new BitmapMetadata("xmpbag"));
for (var i = 0; i < keywordArray.Length; i++)
{
var order = "/{ulong=" + i + "}";
var keyword = keywordArray[i];
metadata.SetQuery("/xmp/<xmpbag>dc:Subject" + order, keyword);
}
// Write in the IPTC section
metadata.SetQuery("/app13/irb/8bimiptc/iptc/{str=Keywords}", keywordArray);
// Create a bitmap encoder
var encoder = CreateBitmapEncoder(imageFormat);
// Create new frame with the updated metadata
// Keep everything the same except the updated metadata
encoder.Frames.Add(BitmapFrame.Create(
bitmapFrame, bitmapFrame.Thumbnail, metadata, bitmapFrame.ColorContexts));
// Attemp to save the update image
using (Stream outputFile = File.Open(path + tempSufix, FileMode.Create, FileAccess.ReadWrite))
{
encoder.Save(outputFile);
}
}
}