Click here to Skip to main content
15,892,697 members
Articles / Programming Languages / C#

Access image metadata using Visual Studio's new object data binding feature

Rate me:
Please Sign up or sign in to vote.
4.85/5 (13 votes)
1 Feb 200712 min read 83.3K   975   46  
Using a new class library to bind to photo metadata with a few line of code.
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Xml;
namespace Reynsoft.PhotoInfo
{
    /// <summary>
    /// The metadata class
    /// </summary>
    public class PhotoshopMetadata : PhotoMetadata
    {
        /// <summary>
        /// Private constructor to enforce the factory pattern.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="doc"></param>
        private PhotoshopMetadata(XmlNode node, XmlDocument doc): base(node, doc)
	    {
 	    }

        /// <summary>
        /// The public factory method.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="doc"></param>
        /// <returns></returns>
        public static PhotoshopMetadata CreateNewPhotoshopMetadata(XmlNode node, XmlDocument doc)
	    {
            if (node == null)
            {
                XmlNode emptyNode = CreateEmptyNode("xmlns:photoshop", "http://ns.adobe.com/photoshop/1.0/", doc);
                return new PhotoshopMetadata(emptyNode, doc);
            }
            else
            {
                return new PhotoshopMetadata(node, doc);
            }
	    }
		#region Generated property definitions

		private string m_AuthorsPosition = null;
		/// <summary>
		/// By-line title.
		/// </summary>
		public string AuthorsPosition
		{
			get
			{
				return m_AuthorsPosition;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_AuthorsPosition)
				{
					m_AuthorsPosition = adjustedValue;
					ElementUpdated("AuthorsPosition", "photoshop:AuthorsPosition", "Text", adjustedValue);
				}
			}
		}

		private string m_CaptionWriter = null;
		/// <summary>
		/// Writer/editor.
		/// </summary>
		public string CaptionWriter
		{
			get
			{
				return m_CaptionWriter;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_CaptionWriter)
				{
					m_CaptionWriter = adjustedValue;
					ElementUpdated("CaptionWriter", "photoshop:CaptionWriter", "ProperName", adjustedValue);
				}
			}
		}

		private string m_Category = null;
		/// <summary>
		/// Category. Limited to 3 7-bit ASCII characters.
		/// </summary>
		public string Category
		{
			get
			{
				return m_Category;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Category)
				{
					m_Category = adjustedValue;
					ElementUpdated("Category", "photoshop:Category", "Text", adjustedValue);
				}
			}
		}

		private string m_City = null;
		/// <summary>
		/// City.
		/// </summary>
		public string City
		{
			get
			{
				return m_City;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_City)
				{
					m_City = adjustedValue;
					ElementUpdated("City", "photoshop:City", "Text", adjustedValue);
				}
			}
		}

		private string m_Country = null;
		/// <summary>
		/// Country/primary location.
		/// </summary>
		public string Country
		{
			get
			{
				return m_Country;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Country)
				{
					m_Country = adjustedValue;
					ElementUpdated("Country", "photoshop:Country", "Text", adjustedValue);
				}
			}
		}

		private string m_Credit = null;
		/// <summary>
		/// Credit.
		/// </summary>
		public string Credit
		{
			get
			{
				return m_Credit;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Credit)
				{
					m_Credit = adjustedValue;
					ElementUpdated("Credit", "photoshop:Credit", "Text", adjustedValue);
				}
			}
		}

		private string m_DateCreated = null;
		/// <summary>
		/// The date the intellectual content of the document was
		/// created (rather than the creation date of the physical
		/// representation), following IIM conventions. For example, a
		/// photo taken during the American Civil War would have a
		/// creation date during that epoch (1861-1865) rather than the
		/// date the photo was digitized for archiving.
		/// </summary>
		public string DateCreated
		{
			get
			{
				return m_DateCreated;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_DateCreated)
				{
					m_DateCreated = adjustedValue;
					ElementUpdated("DateCreated", "photoshop:DateCreated", "Date", adjustedValue);
				}
			}
		}

		private string m_Headline = null;
		/// <summary>
		/// Headline.
		/// </summary>
		public string Headline
		{
			get
			{
				return m_Headline;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Headline)
				{
					m_Headline = adjustedValue;
					ElementUpdated("Headline", "photoshop:Headline", "Text", adjustedValue);
				}
			}
		}

		private string m_Instructions = null;
		/// <summary>
		/// Special instructions.
		/// </summary>
		public string Instructions
		{
			get
			{
				return m_Instructions;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Instructions)
				{
					m_Instructions = adjustedValue;
					ElementUpdated("Instructions", "photoshop:Instructions", "Text", adjustedValue);
				}
			}
		}

		private string m_Source = null;
		/// <summary>
		/// Source.
		/// </summary>
		public string Source
		{
			get
			{
				return m_Source;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Source)
				{
					m_Source = adjustedValue;
					ElementUpdated("Source", "photoshop:Source", "Text", adjustedValue);
				}
			}
		}

		private string m_State = null;
		/// <summary>
		/// Province/state.
		/// </summary>
		public string State
		{
			get
			{
				return m_State;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_State)
				{
					m_State = adjustedValue;
					ElementUpdated("State", "photoshop:State", "Text", adjustedValue);
				}
			}
		}

		private string m_SupplementalCategories = null;
		/// <summary>
		/// Supplemental category.
		/// </summary>
		public string SupplementalCategories
		{
			get
			{
				return m_SupplementalCategories;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_SupplementalCategories)
				{
					m_SupplementalCategories = adjustedValue;
					ElementUpdated("SupplementalCategories", "photoshop:SupplementalCategories", "bag Text", adjustedValue);
				}
			}
		}

		private string m_TransmissionReference = null;
		/// <summary>
		/// Original transmission reference.
		/// </summary>
		public string TransmissionReference
		{
			get
			{
				return m_TransmissionReference;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_TransmissionReference)
				{
					m_TransmissionReference = adjustedValue;
					ElementUpdated("TransmissionReference", "photoshop:TransmissionReference", "Text", adjustedValue);
				}
			}
		}

		private string m_Urgency = null;
		/// <summary>
		/// Urgency. Valid range is 1-8.
		/// </summary>
		public string Urgency
		{
			get
			{
				return m_Urgency;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Urgency)
				{
					m_Urgency = adjustedValue;
					ElementUpdated("Urgency", "photoshop:Urgency", "Integer", adjustedValue);
				}
			}
		}
		#endregion
		#region Generated function to initialize properties
        /// <summary>
        /// Generated function to initialize properties
        /// </summary>
        public override void LoadInitialData()
		{
			this.m_AuthorsPosition = GetInitialValue("photoshop:AuthorsPosition", "Text");
			NotifyPropertyChanged("AuthorsPosition");
			this.m_CaptionWriter = GetInitialValue("photoshop:CaptionWriter", "ProperName");
			NotifyPropertyChanged("CaptionWriter");
			this.m_Category = GetInitialValue("photoshop:Category", "Text");
			NotifyPropertyChanged("Category");
			this.m_City = GetInitialValue("photoshop:City", "Text");
			NotifyPropertyChanged("City");
			this.m_Country = GetInitialValue("photoshop:Country", "Text");
			NotifyPropertyChanged("Country");
			this.m_Credit = GetInitialValue("photoshop:Credit", "Text");
			NotifyPropertyChanged("Credit");
			this.m_DateCreated = GetInitialValue("photoshop:DateCreated", "Date");
			NotifyPropertyChanged("DateCreated");
			this.m_Headline = GetInitialValue("photoshop:Headline", "Text");
			NotifyPropertyChanged("Headline");
			this.m_Instructions = GetInitialValue("photoshop:Instructions", "Text");
			NotifyPropertyChanged("Instructions");
			this.m_Source = GetInitialValue("photoshop:Source", "Text");
			NotifyPropertyChanged("Source");
			this.m_State = GetInitialValue("photoshop:State", "Text");
			NotifyPropertyChanged("State");
			this.m_SupplementalCategories = GetInitialValue("photoshop:SupplementalCategories", "bag Text");
			NotifyPropertyChanged("SupplementalCategories");
			this.m_TransmissionReference = GetInitialValue("photoshop:TransmissionReference", "Text");
			NotifyPropertyChanged("TransmissionReference");
			this.m_Urgency = GetInitialValue("photoshop:Urgency", "Integer");
			NotifyPropertyChanged("Urgency");
		}
		#endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This is a picture of John still in the cubicled environment of the Northern Virginia tech world. There are great software jobs there, but the traffic is horrible! He has since retired, or really, started a new, freer lifestyle. He now travels and takes photographs. At home, he is involved in a number of community activities including work at the Historical Society of Frederick County (MD) where he has helped preserve historic documents and photographs by making photographic copies. Some of them are posted on the HSFC photo catalog website. He is fascinated by the new ability, using applications like Google Earth, to link photos to geographic locations. This adds a new dimension to photography, which he is working to develop. These pursuits, which require the ability to access and manage photo metadata, are a major motivation for getting involved as deeply as he did in this exciting topic.

Comments and Discussions