Search code examples
c#metadatajpegphotoshopxmp

Jpeg writing xmp for null property


I have a program which can read xmp Data in C# but some images have some properties NULL and when I am trying to write xmp data for a NULL property it gives an exception:

Property cannot be found :Exception from HRESULT: 0x88982F40

Is it possible to set values for properties which are NULL?

// Credit Status = Copyrighted
metaData.SetQuery("/xmp/xmpRights:Marked", "True");

//overwriting instructions with static text
metaData.SetQuery("/xmp/photoshop:Instructions", Constants.InstructionsText);

var usageTerms = metaData.GetQuery("/xmp/xmpRights:UsageTerms/x-default");

if (string.IsNullOrEmpty(Convert.ToString(usageTerms)))
    metaData.SetQuery("/xmp/xmpRights:UsageTerms/x-default", Constants.UsageTermText);

Basically i need a script through which i can create a new XMP property in Jpeg?


Solution

  • I have found a way, I hope it helps! I found the answer on MSDN comments

    if (!metadata.ContainsQuery(@"/xmp/photoshop:Instructions"))
         metadata.SetQuery(@"/xmp/{wstr=http://ns.adobe.com/photoshop/1.0/}:Instructions", instructions);
    if (metadata.ContainsQuery("/xmp/photoshop:Marked"))
         metadata.SetQuery(@"/xmp/{wstr=http://ns.adobe.com/photoshop/1.0/}:Marked", CreditStatus);
    if (metadata.ContainsQuery("/xmp/xmpRights:UsageTerms/x-default"))
    {
         metadata.SetQuery(@"/xmp/{wstr=http://ns.adobe.com/xap/1.0/rights/}:UsageTerms",
                                              new BitmapMetadata("xmpalt"));
         metadata.SetQuery(@"/xmp/xmpRights:UsageTerms/x-default", usageTerms);
    }