Click here to Skip to main content
15,892,768 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>
    /// Dublin Core metadata class
    /// </summary>
    public class DcMetadata : PhotoMetadata
    {
        /// <summary>
        /// Private constructor to enforce the factory pattern.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="doc"></param>
        private DcMetadata(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 DcMetadata CreateNewDcMetadata(XmlNode node, XmlDocument doc)
	    {
            if (node == null)
            {
                XmlNode emptyNode = CreateEmptyNode("xmlns:dc", "http://purl.org/dc/elements/1.1/", doc);
                return new DcMetadata(emptyNode, doc);
            }
            else
            {
                return new DcMetadata(node, doc);
            }
	    }

		#region Generated property definitions

		private string m_Contributor = null;
		/// <summary>
		/// Contributors to the resource (other than the authors).
		/// </summary>
		public string Contributor
		{
			get
			{
				return m_Contributor;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Contributor)
				{
					m_Contributor = adjustedValue;
					ElementUpdated("Contributor", "dc:contributor", 
                        "bag ProperName", adjustedValue);
				}
			}
		}

		private string m_Coverage = null;
		/// <summary>
		/// The extent or scope of the resource.
		/// </summary>
		public string Coverage
		{
			get
			{
				return m_Coverage;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Coverage)
				{
					m_Coverage = adjustedValue;
					ElementUpdated("Coverage", "dc:coverage", "Text", adjustedValue);
				}
			}
		}

		private string m_Creator = null;
		/// <summary>
		/// The authors of the resource (listed in order of precedence,
		/// if significant).
		/// </summary>
		public string Creator
		{
			get
			{
				return m_Creator;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Creator)
				{
					m_Creator = adjustedValue;
					ElementUpdated("Creator", "dc:creator", "seq ProperName", adjustedValue);
				}
			}
		}

		private string m_Date = null;
		/// <summary>
		/// Date(s) that something interesting happened to the resource.
		/// </summary>
		public string Date
		{
			get
			{
				return m_Date;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Date)
				{
					m_Date = adjustedValue;
					ElementUpdated("Date", "dc:date", "seq Date", adjustedValue);
				}
			}
		}

		private string m_Description = null;
		/// <summary>
		/// A textual description of the content of the resource.
		/// Multiple values may be present for different languages.
		/// </summary>
		public string Description
		{
			get
			{
				return m_Description;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Description)
				{
					m_Description = adjustedValue;
					ElementUpdated("Description", "dc:description", "Lang Alt", adjustedValue);
				}
			}
		}

		private string m_Format = null;
		/// <summary>
		/// The file format used when saving the resource. Tools and
		/// applications should set this property to the save format of
		/// the data. It may include appropriate qualifiers.
		/// </summary>
		public string Format
		{
			get
			{
				return m_Format;
			}
		}

		private string m_Identifier = null;
		/// <summary>
		/// Unique identifier of the resource.
		/// </summary>
		public string Identifier
		{
			get
			{
				return m_Identifier;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Identifier)
				{
					m_Identifier = adjustedValue;
					ElementUpdated("Identifier", "dc:identifier", "Text", adjustedValue);
				}
			}
		}

		private string m_Language = null;
		/// <summary>
		/// An unordered array specifying the languages used in the
		/// resource.
		/// </summary>
		public string Language
		{
			get
			{
				return m_Language;
			}
		}

		private string m_Publisher = null;
		/// <summary>
		/// Publishers.
		/// </summary>
		public string Publisher
		{
			get
			{
				return m_Publisher;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Publisher)
				{
					m_Publisher = adjustedValue;
					ElementUpdated("Publisher", "dc:publisher", "bag ProperName", adjustedValue);
				}
			}
		}

		private string m_Rights = null;
		/// <summary>
		/// Informal rights statement, selected by language.
		/// </summary>
		public string Rights
		{
			get
			{
				return m_Rights;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Rights)
				{
					m_Rights = adjustedValue;
					ElementUpdated("Rights", "dc:rights", "Lang Alt", adjustedValue);
				}
			}
		}

		private string m_Source = null;
		/// <summary>
		/// Unique identifier of the work from which this resource was
		/// derived.
		/// </summary>
		public string Source
		{
			get
			{
				return m_Source;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Source)
				{
					m_Source = adjustedValue;
					ElementUpdated("Source", "dc:source", "Text", adjustedValue);
				}
			}
		}

		private string m_Subject = null;
		/// <summary>
		/// An unordered array of descriptive phrases or keywords that
		/// specify the topic of the content of the resource.
		/// </summary>
		public string Subject
		{
			get
			{
				return m_Subject;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Subject)
				{
					m_Subject = adjustedValue;
					ElementUpdated("Subject", "dc:subject", "bag Text", adjustedValue);
				}
			}
		}

		private string m_Title = null;
		/// <summary>
		/// The title of the document, or the name given to the
		/// resource. Typically, it will be a name by which the resource
		/// is formally known.
		/// </summary>
		public string Title
		{
			get
			{
				return m_Title;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Title)
				{
					m_Title = adjustedValue;
					ElementUpdated("Title", "dc:title", "Lang Alt", adjustedValue);
				}
			}
		}

		private string m_Type = null;
		/// <summary>
		/// A document type; for example, novel, poem, or working paper.
		/// </summary>
		public string Type
		{
			get
			{
				return m_Type;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Type)
				{
					m_Type = adjustedValue;
					ElementUpdated("Type", "dc:type", "bag open Choice", adjustedValue);
				}
			}
		}
		#endregion
		#region Generated function to initialize properties
        /// <summary>
        /// Generated function to initialize properties
        /// </summary>
		public override void LoadInitialData()
		{
			this.m_Contributor = GetInitialValue("dc:contributor", "bag ProperName");
			NotifyPropertyChanged("Contributor");
			this.m_Coverage = GetInitialValue("dc:coverage", "Text");
			NotifyPropertyChanged("Coverage");
			this.m_Creator = GetInitialValue("dc:creator", "seq ProperName");
			NotifyPropertyChanged("Creator");
			this.m_Date = GetInitialValue("dc:date", "seq Date");
			NotifyPropertyChanged("Date");
			this.m_Description = GetInitialValue("dc:description", "Lang Alt");
			NotifyPropertyChanged("Description");
			this.m_Format = GetInitialValue("dc:format", "MIMEType");
			NotifyPropertyChanged("Format");
			this.m_Identifier = GetInitialValue("dc:identifier", "Text");
			NotifyPropertyChanged("Identifier");
			this.m_Language = GetInitialValue("dc:language", "bag Locale");
			NotifyPropertyChanged("Language");
			this.m_Publisher = GetInitialValue("dc:publisher", "bag ProperName");
			NotifyPropertyChanged("Publisher");
			this.m_Rights = GetInitialValue("dc:rights", "Lang Alt");
			NotifyPropertyChanged("Rights");
			this.m_Source = GetInitialValue("dc:source", "Text");
			NotifyPropertyChanged("Source");
			this.m_Subject = GetInitialValue("dc:subject", "bag Text");
			NotifyPropertyChanged("Subject");
			this.m_Title = GetInitialValue("dc:title", "Lang Alt");
			NotifyPropertyChanged("Title");
			this.m_Type = GetInitialValue("dc:type", "bag open Choice");
			NotifyPropertyChanged("Type");
		}
		#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