How do I read and write XMP metadata in C#?
<p>I have this method for resizing images, and I have managed to input all of the metadata into the new image except for the XMP data. Now, I can only find topics on how manage the XMP part in C++ but I need it in C#. The closest I've gotten is the <a href="https://github.com/Metrilus/xmp-sharp" rel="nofollow">xmp-sharp project</a> which is based on some old port of Adobe's SDK, but I can't get that working for me. The <a href="https://github.com/drewnoakes/metadata-extractor-dotnet" rel="nofollow">MetaDataExtractor project</a> gives me the same results - that is, file format/encoding not supported. I've tried this with .jpg, .png and .tif files.</p>

<p>Is there no good way of reading and writing XMP in C#?</p>

<p>Here is my code if it's of any help (omitting all irrelevant parts):</p>

<pre><code>public Task&lt;Stream&gt; Resize(Size size, Stream image)
{
  using (var bitmap = Image.FromStream(image))
  {
    var newSize = new Size(size.Width, size.Height);
    var ms = new MemoryStream();
    using (var bmPhoto = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format24bppRgb))
    {
      // This saves all metadata except XMP
      foreach (var id in bitmap.PropertyIdList)
        bmPhoto.SetPropertyItem(bitmap.GetPropertyItem(id));

      // Trying to use xmp-sharp for the XMP part
      try
      {
        IXmpMeta xmp = XmpMetaFactory.Parse(image);
      }
      catch (XmpException e)
      {
        // Here, I always get "Unsupported Encoding, XML parsing failure"
      }

      // Trying to use MetadataExtractor for the XMP part
      try
      {
         var xmpDirs = ImageMetadataReader.ReadMetadata(image).Where(d =&gt; d.Name == "XMP");
      }
      catch (Exception e)
      {
        // Here, I always get "File format is not supported"
      }

      // more code to modify image and save to stream
    }
    ms.Position = 0;
    return Task.FromResult&lt;Stream&gt;(ms);
  }
}
</code></pre>