AkVenu AkVenu - 9 months ago 60
C# Question

Getting custom XMP metadata using metadata-extractor in c#

I am writing some XMP metadata using a photoshop .jsx script using :

var xmp = new XMPMeta( activeDocument.xmpMetadata.rawData);
XMPMeta.registerNamespace(nameSpace, nsPrefix);

and then adding some data to this new namespace. I am able to view it in Photoshop by checking under
File -> FileInfo
. My question is how can I access this data using the metadata extractor library in my c# project ? When I use the following code I do not see the new metadata I added inside any of the directories:

FileStream OriginalFile = new FileStream("C:\\Users\\av\\Desktop\\test.tif", FileMode.Open, FileAccess.Read, FileShare.Read);
IEnumerable<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(OriginalFile);


XMP data is stored in the XmpDirectory. Access it via:

var xmpDirectory = ImageMetadataReader.ReadMetadata("path\test.tif")

Note however that XMP data in metadata-extractor does not follow the standard tag/value format of other directories. Instead, you should access the XmpMeta property of the directory in order to inspect that data.

You can then write code resembling:

foreach (var property in xmpDirectory.XmpMeta.Properties)
    Console.WriteLine($"Path={property.Path} Namespace={property.Namespace} " +

Some more discussion here and more information about the XMP library here.