TASSOGRAPHY

Photography and More
by Ben Vincent
TransparentPadder

Share On FacebookShare On Facebook
 
Ben's Blog (71)Ben's Blog (71)
Development (16)Development (16)
Lisa's Blog (6)Lisa's Blog (6)
 
Show All (94)Show All (94)
 
Jun 2010 (4)Jun 2010 (4)
May 2010 (2)May 2010 (2)
Apr 2010 (7)Apr 2010 (7)
Mar 2010 (5)Mar 2010 (5)
Feb 2010 (1)Feb 2010 (1)
Jan 2010 (3)Jan 2010 (3)
Nov 2009 (8)Nov 2009 (8)
Oct 2009 (4)Oct 2009 (4)
Sep 2009 (4)Sep 2009 (4)
Jul 2009 (6)Jul 2009 (6)
Jun 2009 (5)Jun 2009 (5)
May 2009 (7)May 2009 (7)
Mar 2009 (1)Mar 2009 (1)
Feb 2009 (5)Feb 2009 (5)
Jan 2009 (7)Jan 2009 (7)
Dec 2008 (6)Dec 2008 (6)
Oct 2008 (3)Oct 2008 (3)
Sep 2008 (3)Sep 2008 (3)
Aug 2008 (9)Aug 2008 (9)
Jul 2008 (3)Jul 2008 (3)
Jun 2008 (1)Jun 2008 (1)
 
Show All (94)Show All (94)
 
RSS & Atom FeedsRSS & Atom Feeds




TransparentPadder
Home Job Runner Image Usage Tracker Image Blog   |   Highlights   |   Photography   |   Contact   |   About    Atom & RSS Feeds  

Basic Editing of Photo Metadata Using Windows Imaging Component by Ben Vincent

In my previous posts I’ve provided examples on using Windows Imaging Component to Read & Write jpg metadata. In this post I’ll explain how to use ContainsQuery, GetQuery, SetQuery and RemoveQuery. As an added bonus I’m going to use the IPTC address fields as my example.

Whilst BitmapMetadata does provide some standard properties like Subject and Title, it is far from comprehensive. In order to get at the other data you have to provide the right query. For me this has been one of the most frustrating challenges because these queries are not what you’d call logical. I’m going use a few basic queries in this post but I will be posting all the queries I use in a later post. These four queries give you access to the Country, Region, City and SubLocation IPTC tags.

// Queries for the IPTC Address fields
// Note: Region is normally the State or County
string iptcCountry = @"/app13/irb/8bimiptc/iptc/Country\/Primary Location Name";
string iptcRegion = @"/app13/irb/8bimiptc/iptc/Province\/State";
string iptcCity = @"/app13/irb/8bimiptc/iptc/City";
string iptcSubLocation = @"/app13/irb/8bimiptc/iptc/Sub-location";

Now let’s start with ContainsQuery and GetQuery which form the basics of your use of the BitmapMetadata class.

In this example we query the BitmapMetadata object for the IPTC City. First we read the file, then check the file contains data for the IPTC City and if it does write it to the debug console:

// Grab copy of BitmapMetadata
BitmapMetadata bitmapMetadata = StandaloneWpfReader.ReadMetadata(inputFile);

// Check there's city data
if (bitmapMetadata.ContainsQuery(iptcCity))
{
    // Dump it to the console
    Debug.WriteLine(bitmapMetadata.GetQuery(iptcCity));
}

That code provides the core of manipulating the file. Now lets deal with SetQuery:

// Grab copy of BitmapMetadata and add Padding
BitmapMetadata bitmapMetadata = this.ReadMetadata("TestInput.jpg");
StandaloneWpfReader.AddMetadataPadding(bitmapMetadata, 5012);

// Use SetQuery to store the IPTC Address fields
bitmapMetadata.SetQuery(iptcCity, "IPTC City");
bitmapMetadata.SetQuery(iptcCountry, "IPTC Country");
bitmapMetadata.SetQuery(iptcRegion, "IPTC Region");
bitmapMetadata.SetQuery(iptcSubLocation, "IPTC SubLocation");

// Save the new file
this.WriteMetadata("TestInput.jpg", "TestOutput.jpg", bitmapMetadata);

And finally, the pretty obvious RemoveQuery, were we’ll remove the data we’ve just added:

// Remove IPTC Address fields
bitmapMetadata.RemoveQuery(iptcCity);
bitmapMetadata.RemoveQuery(iptcCountry);
bitmapMetadata.RemoveQuery(iptcRegion);
bitmapMetadata.RemoveQuery(iptcSubLocation);

That’s it for the basic manipulation, in future blogs I’ll build on this to explain how to work with more complicated metadata.


Posted: Thu, 5 Nov 2009, 05:09:10 GMT Updated: Thu, 5 Nov 2009, 05:25:28 GMT by Ben Vincent
Category: Development
Tags: Windows Imaging Component, XMP, Exif, IPTC, Fotofly


TransparentPadder TransparentPadder TransparentPadder

Tweet  Ben - Cool! A nice end to the week, my mum was waiting for me in St Louis, she kept it a secret!

(Updated: Fri, 30 Jul 2010, 23:10:30)

Alcatraz . American Express . Amusing Photos . ASP.Net MVC . Australia . Bing . Blue Angels . BMi . Breathe Magazine . British Food . British Virgin Islands . California Highway Patrol . Camping . Canada . Christmas . Christmas Tree . Cleaner Shrimp . codeplex . Cooking . Coral Sea . Diving . Dragonlance . Engagement . Exif . Expedia . Facebook . Fish Tank . Flying . Food . Fotofly . Geotagging . Golden Gate National Recreation Area . Google . Gordon Ramsay . Hotmail . IPTC . Michelin Star . Microsoft . Microsoft Giving Campaign . Monterey Bay Aquarium . Mountain Biking . Nudibranch . San Francisco . Search Engine Optimzation (SEO) . Ship Wrecks . Silverlight . Starbucks . Tassography . The Sea Nettle Jelly . TransRockies . TV Commercial . United Airlines . Usage . Windows 7 . Windows Imaging Component . Windows Live . Windows Live Calendar . Windows Live Photo Gallery . Wineries . XMP


This website, all photography & other content is Copyright © Ben Vincent. Unauthorised use of images is strictly prohibited.
Catalog Last Updated: Mon, 19 Jul 2010, 22:48:43    |   Version v4.0.3861.38195
Powered by
Fotofly Logo