I am trying to add custom XMP metadata to JPG files via BitmapMetadata.SetQuery. My code works fine for modifying predefined metadata but I am stuck on trying to use a custom schema in a namespace. I have read the relevent portions of the XMP spec but don't see any exposed methods to define a custom namespace in the metadata. I tried this WAG approach:
BitmapMetadata metadata = frame.Metadata.Clone() as BitmapMetadata; // I figure I only need to pad /XMP but for now I pad EVERYTHING metadata.SetQuery("/app1/ifd/PaddingSchema:Padding", paddingAmount); metadata.SetQuery("/app1/ifd/exif/PaddingSchema:Padding", paddingAmount); metadata.SetQuery("/xmp/PaddingSchema:Padding", paddingAmount); // Now add data using my totally made up namespace. metadata.SetQuery("/xmp/NX:NXData", "Hello World");
This "works" in that SetQuery succeeds but when I try to save the file I get an overflow exception. If I change the query to a known good metadata field it works fine. I hope I am missing something obvious here but nothing about this project has been obvious so far...
My assumption is that the overflow is related to the padding or padding amont you are setting. The app1 segment in JPEG can only contain 64K worth of data, and this includes the thumbnail data, so if you set padding too high you could easily trigger an exception. Your XMP query looks sound (just setting a simple property at the xmp root), so try again without the padding to be sure.
Proposed As Answer byElliott PrechterWednesday, November 18, 2009 7:36 PM