Click here to Skip to main content
14,267,298 members

Reading and Writing Photo Metadata Programmatically Using Microsoft Pro Photo Tools

Rate this:
4.81 (11 votes)
Please Sign up or sign in to vote.
4.81 (11 votes)
24 Oct 2009CPOL
A way to update photo metadata (EXIF, XMP, IPTC, etc.) using the DLLs used by Microsoft Pro Photo Tools.


Tinkering with an image (JPG, TIFF, or even RAW) file's metadata (EXIF, IPTC, XMP, et. al.) is probably one of the not-so-common tasks a .NET developer has to mess around with, but on those occasions where it is needed, it is surprising to know that there are not a lot of options around. ImageMagick's .NET implementation isn't exactly updated (as far as I know), and there is no clear information on how to use it without having to see a shrink afterwards.

I have been faced with this challenge of programmatically updating image metadata, and the idea of using ImageMagick scared me. Fortunately, I have discovered a better way to do it using Microsoft's own free tools.

Please note that none of these are based on the documented .NET SDK supported by Microsoft. They could change this anytime they want, so be aware of this fact should you decide to use the code in a production environment.


Microsoft has introduced this nifty tool to view/edit image metadata called the Pro Photo Tools 2.0. It's a freeware that is used to view update the EXIF/IPTC/XMP information of a wide range of image formats, including proprietary RAW formats from camera manufacturers. The tool comes with a number of DLLs that I will be using to view/update metadata in a C# application.

This requires the extensive use of the .NET Reflector and Visual Studio's debugger...and the usual screaming and cursing in front of the computer during the discovery process. ;-)

I have to be honest, this idea isn't exactly original. There has been a forum discussion somewhere on the intarwebs on using the DLLs bundled with the first version of Pro Photo Tools (called PhotoInfo). There has been a radical change with the way Microsoft deals with metadata from version 1.0 to 2.0, so I figured writing an article about it may be worthwhile.

Setting it Up

Download and install the Microsoft Pro Photo Tools 2.0 software and then fire up your Visual Studio 2008. Create a C# Console Application and reference Microsoft.ImageMetadata.dll from the %PROGRAMFILES%\Microsoft Pro Photo Tools directory. This DLL contains all the good stuff for reading and writing image metadata.

Dissecting the Pro Photo Tools DLLs

This requires a little bit of .NET Reflector ninja skills. Open Microsoft.ProPhotoToolsFoundation.dll and browse to the Resources folder, and save Microsoft.PhotoToolboxFoundation.ToolboxPolicy.xml to a local directory in your computer. We will make a reference to this file somewhere in the C# code that you will write.


The Code

Believe it or not, the hard part is done! Referencing the DLL. Now, you will just need to write this code in your test C# application:

  var img_path = @"@C:\[PATH TO YOUR IMAGE FILE].jpg";
  var p = (new MetadataPolicyManager()).loadPolicy(@"C:\[PATH TO POLICY FILE]" + 
  imgProxy = new ImageFileProxy(img_path, p); 
  object desc = imgProxy.Data[p.getTagIndex("Description")];
  Console.WriteLine("Description: " + desc.ToString());
  imgProxy.Data[p.getTagIndex("Description")] = "Description modified!"; 
catch (Exception ex) 
  // write exception handler 

img_path is the path to the image file that you want to inspect/change the metadata of. And, remember the policy XML you extracted using .NET Reflector? You point loadPolicy() to that location.

What Happened Here?

As you can see, not much is going on here when you run the application: you extracted the description from the image metadata and displayed it in the console screen. That's it!

That's it?

Yes, uneventful as it seems, that is all there is to it. That's the beauty of it: the simplicity! imgProxy (ImageFileProxy) pretty much takes the grunt work of loading the metadata into memory, and the imgProxy.Data (an array) is the blob that contains all the image metadata. If you run the application through the debugger and inspect imgProxy, you will see the rest of your image metadata! Not only that, the array contains objects that represent the data deserialized for you, not just some series of bytes that you need to format for display.

So What's with the Policy File?

Here is where the magic happens. I still haven't understood it fully, but suffice to say, it deals with all the "mappings" between the image metadata and the location of the metadata from within the header of the image file. You don't need to know the "location" of the metadata (regardless of whether its XMP, IPTC, or EXIF!), p.GetTagIndex() does it for you! If you need to know the rest of the metadata keywords, all you need to do is take a peek of the policy XML file. Here are some of the keywords available:

  • Description
  • Keywords
  • Copyright
  • Rating
  • SubjectReference
  • Source
  • Category
  • CaptureDate

Updating the Metadata

As you might have noticed by now, imgProxy.Data is read/write. To update the metadata, simply assign a new value or values, then call imgProxy.commit(). Again, the simplicity is the major selling point here.

Anything Else?

Reading/updating the image metadata is one of the tricks that are offered by the Pro Photo Tools DLLs. As you inspect the DLL, there are also means to do GeoTagging, given your photo's Longitude and Latitude information in the header are present. Of course, that is beyond the scope of this article; I leave that to the adventurous .NET developer should he/she need those features in their .NET application.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Dexter Legaspi
Software Developer (Senior)
United States United States
I have dabbling with Microsoft Technologies far longer than I want to admit. Smile | :) My main area of expertise is in the field of integration and most of them are implemented using Microsoft BizTalk.

When I'm not busy with my day job I can usually be seen in front of my Playstation or out somewhere with my camera. Wink | ;-)

Comments and Discussions

QuestionHow insert large amount of data in metadata? Pin
haidreza26-Jun-13 21:42
memberhaidreza26-Jun-13 21:42 
QuestionValue does not fall within the expected range Pin
Member 938339315-Apr-13 6:12
memberMember 938339315-Apr-13 6:12 
AnswerRe: Value does not fall within the expected range Pin
Scotty Walkin13-Nov-16 21:58
memberScotty Walkin13-Nov-16 21:58 
QuestionIts Working fine Pin
sameerpatel9-Apr-13 0:23
membersameerpatel9-Apr-13 0:23 
QuestionIllegal class definiton Pin
noah34326630-Dec-12 3:40
membernoah34326630-Dec-12 3:40 
GeneralMy vote of 5 Pin
Dell.Simmons25-Sep-12 10:17
memberDell.Simmons25-Sep-12 10:17 Code Conversion Pin
CharlesMichaelWilliams15-Sep-12 0:26
memberCharlesMichaelWilliams15-Sep-12 0:26 
Questionusing ??? Pin
Martin197217-Mar-12 2:30
memberMartin197217-Mar-12 2:30 
AnswerRe: using ??? Pin
Dexter Legaspi9-Apr-12 13:19
memberDexter Legaspi9-Apr-12 13:19 
QuestionRe: using ??? Pin
whohastaken19-Feb-13 19:16
memberwhohastaken19-Feb-13 19:16 
AnswerRe: using ??? Pin
Member 93833936-Apr-13 12:28
memberMember 93833936-Apr-13 12:28 
Questioncareful of a memory leak Pin
ljb123426-Oct-11 4:48
memberljb123426-Oct-11 4:48 
AnswerRe: careful of a memory leak Pin
Dexter Legaspi26-Oct-11 5:20
memberDexter Legaspi26-Oct-11 5:20 
Generalerror when trying to write data to caption that does not exist Pin
bikeless9-Nov-10 21:43
memberbikeless9-Nov-10 21:43 
QuestionInterop.PptNative error Pin
garytian5520-Jul-10 22:53
groupgarytian5520-Jul-10 22:53 
GeneralStrong name of Microsoft.ImageMetadata.dll Pin
garytian5518-Jul-10 16:42
groupgarytian5518-Jul-10 16:42 
GeneralGetting rid of a date Pin
rctaubert8-Jul-10 12:11
memberrctaubert8-Jul-10 12:11 
GeneralText Encoding Pin
kuddel33214-Apr-10 0:57
memberkuddel33214-Apr-10 0:57 
GeneralCan´t find file Pin
henur13-Feb-10 23:30
memberhenur13-Feb-10 23:30 
GeneralRe: Can´t find file Pin
Dexter Legaspi14-Feb-10 2:24
memberDexter Legaspi14-Feb-10 2:24 
GeneralRe: Can´t find file Pin
henur14-Feb-10 5:54
memberhenur14-Feb-10 5:54 
Thanks for your rapid answer's not located there. I thought that also, but there is non .xml in that directory , and there is no subdir's either.

So ?

Some other ideas ?

GeneralRe: Can´t find file Pin
ApoloniaK12-Mar-10 2:47
memberApoloniaK12-Mar-10 2:47 
GeneralRe: Can´t find file Pin
Andrew31215-Oct-15 6:22
memberAndrew31215-Oct-15 6:22 
GeneralImageType Object Pin
Member 32831914-Jan-10 22:45
memberMember 32831914-Jan-10 22:45 
GeneralOnly works on your computer Pin
Steini kallinn1-Jan-10 8:27
memberSteini kallinn1-Jan-10 8:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 24 Oct 2009


42 bookmarked