JPEG 2000 XMP metadata not saved

Hi,

Recently I tried to work with XMP data in JPEG 2000 images, but so far have only been able read the contents. If I were to save the image, any XMP metadata previously present simply disappears, even if nothing is touched on the image object. I also tried to add custom elements next to existing metadata, or by creating a new XmpPacketWrapper and/or derivatives of XmpPackage, with no success so far.

I have prepared a sample project, which tries to write the XmpData for a loaded Jpeg2000Image both by providing options for the Save() call, and by directly manipulating the image object and then saving, and also by converting the image to a “plain” JPG. Apparently none of them works, as upon loading, the XmpData is empty, every single time.
Could you please help figure out what could be wrong?

Here is the project with some sample files with and without XmpData embedded using ExifTool:
Jpeg2000Metadata.zip (544.4 KB)

Thanks in advance for your assistance!

Regards,
Peter

@psimon ,
We are currently working on cross-format metadata export feature. Jpeg2000 has indeed some flaws in metadata management.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): IMAGINGNET-7098

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@psimon , Issue related to JPEG2000 exists, but you can try use for example jpeg until issue will be fixed

            Rectangle rect = new Rectangle(0, 0, 100, 200);
            XmpPacketWrapper xmpData = CreateXmpData();
            using (Jpeg2000Image jpgImage = new Jpeg2000Image(rect.Width, rect.Height))
            {
                jpgImage.Save(@"c:\Users\USER\Downloads\test.j2k", new Jpeg2000Options() { XmpData = xmpData });
            }
using (Jpeg2000Image image = (Jpeg2000Image)Image.Load(@"c:\Users\USER\Downloads\test.j2k"))
            {
                Console.WriteLine(image.XmpData.Meta.GetAttribute("Author"));                
            }

private static XmpPacketWrapper CreateXmpData()
        {
            XmpHeaderPi xmpHeader = new XmpHeaderPi(System.Guid.NewGuid().ToString());
            XmpTrailerPi xmpTrailer = new XmpTrailerPi(true);

            XmpMeta xmpMeta = new XmpMeta();
            xmpMeta.AddAttribute("Author", "Mr Smith");
            xmpMeta.AddAttribute("Description", "The fake metadata value");

            XmpPacketWrapper xmpData = new XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta);

            PhotoshopPackage photoshopPackage = new PhotoshopPackage();
            photoshopPackage.SetCity("London");
            photoshopPackage.SetCountry("England");
            photoshopPackage.SetColorMode(ColorMode.Rgb);
            photoshopPackage.SetCreatedDate(DateTime.UtcNow);
            xmpData.AddPackage(photoshopPackage);

            DublinCorePackage dublinCorePackage = new DublinCorePackage();
            dublinCorePackage.SetAuthor("Charles Bukowski");
            dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts");
            dublinCorePackage.AddValue("dc:movie", "Barfly");
            xmpData.AddPackage(dublinCorePackage);

            return xmpData;
        }