December 2006 - Posts

Reading XMP MetaData Keywords with WPF

WPF has an interesting way to read metadata associated with a photo.  All metadata can be extracted using the BitmapMetaData object.  The BitmapMetaData object supports the various metadata schemas including: Exif, tEXt, IFD, IPTC and XMP.

Here's a simply way to read an existing image's metada with C#:

BitmapMetadata metadata = (BitmapMetadata)myImage.Source.Metadata;

MessageBox.Show(metadata.Title);

Looking at the BitMapMetaData, you can find out all sorts of information such as camera model, date taken, caption, etc.  In particular, I was interested in reading the Tags added by Windows Photo Gallery in Vista.  The Microsoft Photography Blog article states that "All metadata written to photos by Windows Vista will be written to XMP (always directly to the file itself, never to a ‘sidecar’ file)."  Furthermore, I found that the tags are stored in the keywords collection in the metadata. Simple enough. I expanded my sample yesterday to display the tags associated with an image when it's selected. 

I haven't figured a way to programmatically add new tags to the images yet. I have some code in the demo to add new tags using the InPlaceBitmapMetadataWriter object that doesn't work. Let me know if I'm missing something.

An aside, the demo now also supports multiple files drag and drop.  I also cleaned up the styling a bit.

DragDropMedia2

Source: http://blogs.vertigosoftware.com/files/alan/dragdropmedia.zip

Compiled and Programmed with .NET 3.0 Framework.

posted by AlanL with 4 Comments