Search code examples
metadataxmp

How to preserve XMP metadata in Objective C?


I need my photo-editor app to preserve unknown metadata entries that were existing in the original photo that was opened by my app (for example, non-standard XMP meta-data)

I tried to use the Apple's built-in meta-data read/write meta-data, with no success.

Is there a way to just copy all existing meta-data to a buffer, write it as-is and then change only specific entries?


Solution

  • Yes.

    • Use Adobe XMP SDK.
    • Read the metadata from the image when you open it using:

      SXMPFiles myFile;

      ok = myFile.OpenFile(filename, kXMP_UnknownFile, opts);

      myFile.GetXMP(_meta); // _meta is a data member of the class that represents your photo (probably a subclass of NSDocument).

    • When saving the image, write the image content, then write _meta to the output file using SXMPFiles.PutXMP(...), and then set specific metadata entries that you like.

    See Adobe XMP programming guide for more details about reading and writing XMP metadata.