Click here to Skip to main content
15,893,904 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 TIFF metadata clase
    /// </summary>
    public class TiffMetadata : PhotoMetadata
    {
        /// <summary>
        /// Private constructor to enforce the factory pattern.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="doc"></param>
        private TiffMetadata(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 TiffMetadata CreateNewTiffMetadata(XmlNode node, XmlDocument doc)
	      {
            if (node == null)
            {
                // TODO:  Insert the namespace name and URI for this group.
                //        Leave unchanged if this group is never edited.
                XmlNode emptyNode = CreateEmptyNode("xmlns:tiff", "http://ns.adobe.com/tiff/1.0/", doc);
                return new TiffMetadata(emptyNode, doc);
            }
            else
            {
                return new TiffMetadata(node, doc);
            }
	      }
		#region Generated property definitions

		private string m_ImageWidth = null;
		/// <summary>
		/// TIFF tag 256, 0x100. Image width in pixels.
		/// </summary>
		public string ImageWidth
		{
			get
			{
				return m_ImageWidth;
			}
		}

		private string m_ImageLength = null;
		/// <summary>
		/// TIFF tag 257, 0x101. Image height in pixels.
		/// </summary>
		public string ImageLength
		{
			get
			{
				return m_ImageLength;
			}
		}

		private string m_BitsPerSample = null;
		/// <summary>
		/// TIFF tag 258, 0x102. Number of bits per component in each
		/// channel.
		/// </summary>
		public string BitsPerSample
		{
			get
			{
				return m_BitsPerSample;
			}
		}

		private string m_Compression = null;
		/// <summary>
		/// TIFF tag 259, 0x103. Compression scheme:1 = uncompressed; 6
		/// = JPEG.
		/// </summary>
		public string Compression
		{
			get
			{
				return m_Compression;
			}
		}

		private string m_PhotometricInterpretation = null;
		/// <summary>
		/// TIFF tag 262, 0x106. Pixel Composition: 2 = RGB; 6 = YCbCr.
		/// </summary>
		public string PhotometricInterpretation
		{
			get
			{
				return m_PhotometricInterpretation;
			}
		}

		private string m_Orientation = null;
		/// <summary>
		/// TIFF tag 274, 0x112. Orientation: 1 = 0th row at top, 0th
		/// column at left 2 = 0th row at top, 0th column at right 3 =
		/// 0th row at bottom, 0th column at right 4 = 0th row at
		/// bottom, 0th column at left 5 = 0th row at left, 0th column
		/// at top 6 = 0th row at right, 0th column at top 7 = 0th row
		/// at right, 0th column at bottom 8 = 0th row at left, 0th
		/// column at bottom
		/// </summary>
		public string Orientation
		{
			get
			{
				return m_Orientation;
			}
		}

		private string m_SamplesPerPixel = null;
		/// <summary>
		/// TIFF tag 277, 0x115. Number of components per pixel.
		/// </summary>
		public string SamplesPerPixel
		{
			get
			{
				return m_SamplesPerPixel;
			}
		}

		private string m_PlanarConfiguration = null;
		/// <summary>
		/// TIFF tag 284, 0x11C. Data layout:1 = chunky; 2 = planar.
		/// </summary>
		public string PlanarConfiguration
		{
			get
			{
				return m_PlanarConfiguration;
			}
		}

		private string m_YCbCrSubSampling = null;
		/// <summary>
		/// TIFF tag 530, 0x212. Sampling ratio of chrominance
		/// components: [2, 1] = YCbCr4:2:2 [2, 2] = YCbCr4:2:0
		/// </summary>
		public string YCbCrSubSampling
		{
			get
			{
				return m_YCbCrSubSampling;
			}
		}

		private string m_YCbCrPositioning = null;
		/// <summary>
		/// TIFF tag 531, 0x213. Position of chrominance vs. luminance
		/// components: 1 = centered; 2 = co-sited.
		/// </summary>
		public string YCbCrPositioning
		{
			get
			{
				return m_YCbCrPositioning;
			}
		}

		private string m_XResolution = null;
		/// <summary>
		/// TIFF tag 282, 0x11A. Horizontal resolution in pixels per
		/// unit.
		/// </summary>
		public string XResolution
		{
			get
			{
				return m_XResolution;
			}
		}

		private string m_YResolution = null;
		/// <summary>
		/// TIFF tag 283, 0x11B. Vertical resolution in pixels per unit.
		/// </summary>
		public string YResolution
		{
			get
			{
				return m_YResolution;
			}
		}

		private string m_ResolutionUnit = null;
		/// <summary>
		/// TIFF tag 296, 0x128. Unit used for XResolution and
		/// YResolution. Value is one of: 2 = inches; 3 = centimeters.
		/// </summary>
		public string ResolutionUnit
		{
			get
			{
				return m_ResolutionUnit;
			}
		}

		private string m_TransferFunction = null;
		/// <summary>
		/// TIFF tag 301, 0x12D. Transfer function for image described
		/// in tabular style with 3 * 256 entries.
		/// </summary>
		public string TransferFunction
		{
			get
			{
				return m_TransferFunction;
			}
		}

		private string m_WhitePoint = null;
		/// <summary>
		/// TIFF tag 318, 0x13E. Chromaticity of white point.
		/// </summary>
		public string WhitePoint
		{
			get
			{
				return m_WhitePoint;
			}
		}

		private string m_PrimaryChromaticities = null;
		/// <summary>
		/// TIFF tag 319, 0x13F. Chromaticity of the three primary
		/// colors.
		/// </summary>
		public string PrimaryChromaticities
		{
			get
			{
				return m_PrimaryChromaticities;
			}
		}

		private string m_YCbCrCoefficients = null;
		/// <summary>
		/// TIFF tag 529, 0x211. Matrix coefficients for RGB to YCbCr
		/// transformation.
		/// </summary>
		public string YCbCrCoefficients
		{
			get
			{
				return m_YCbCrCoefficients;
			}
		}

		private string m_ReferenceBlackWhite = null;
		/// <summary>
		/// TIFF tag 532, 0x214. Reference black and white point values.
		/// </summary>
		public string ReferenceBlackWhite
		{
			get
			{
				return m_ReferenceBlackWhite;
			}
		}

		private string m_DateTime = null;
		/// <summary>
		/// TIFF tag 306, 0x132 (primary) and EXIF tag 37520, 0x9290
		/// (subseconds). Date and time of image creation (no time zone
		/// in EXIF), stored in ISO 8601 format, not the original EXIF
		/// format. This property includes the value for the EXIF
		/// SubSecTime attribute. NOTE: This property is stored in XMP
		/// as xmp:ModifyDate.
		/// </summary>
		public string DateTime
		{
			get
			{
				return m_DateTime;
			}
		}

		private string m_ImageDescription = null;
		/// <summary>
		/// TIFF tag 270, 0x10E. Description of the image. NOTE: This
		/// property is stored in XMP as dc:description.
		/// </summary>
		public string ImageDescription
		{
			get
			{
				return m_ImageDescription;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_ImageDescription)
				{
					m_ImageDescription = adjustedValue;
					ElementUpdated("ImageDescription", "tiff:ImageDescription", "Lang Alt", adjustedValue);
				}
			}
		}

		private string m_Make = null;
		/// <summary>
		/// TIFF tag 271, 0x10F. Manufacturer of recording equipment.
		/// </summary>
		public string Make
		{
			get
			{
				return m_Make;
			}
		}

		private string m_Model = null;
		/// <summary>
		/// TIFF tag 272, 0x110. Model name or number of equipment.
		/// </summary>
		public string Model
		{
			get
			{
				return m_Model;
			}
		}

		private string m_Software = null;
		/// <summary>
		/// TIFF tag 305, 0x131. Software or firmware used to generate
		/// image. NOTE: This property is stored in XMP as
		/// xmp:CreatorTool.
		/// </summary>
		public string Software
		{
			get
			{
				return m_Software;
			}
		}

		private string m_Artist = null;
		/// <summary>
		/// TIFF tag 315, 0x13B. Camera owner, photographer or image
		/// creator. NOTE: This property is stored in XMP as the first
		/// item in the dc:creator array.
		/// </summary>
		public string Artist
		{
			get
			{
				return m_Artist;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Artist)
				{
					m_Artist = adjustedValue;
					ElementUpdated("Artist", "tiff:Artist", "ProperName", adjustedValue);
				}
			}
		}

		private string m_Copyright = null;
		/// <summary>
		/// TIFF tag 33432, 0x8298. Copyright information. NOTE: This
		/// property is stored in XMP as dc:rights.
		/// </summary>
		public string Copyright
		{
			get
			{
				return m_Copyright;
			}
			set
			{
				string adjustedValue = AdjustedValue(value);
				if (adjustedValue != m_Copyright)
				{
					m_Copyright = adjustedValue;
					ElementUpdated("Copyright", "tiff:Copyright", "Lang Alt", adjustedValue);
				}
			}
		}
		#endregion
		#region Generated function to initialize properties
        /// <summary>
        /// Generated function to initialize properties
        /// </summary>
        public override void LoadInitialData()
		{
			this.m_ImageWidth = GetInitialValue("tiff:ImageWidth", "Integer");
			NotifyPropertyChanged("ImageWidth");
			this.m_ImageLength = GetInitialValue("tiff:ImageLength", "Integer");
			NotifyPropertyChanged("ImageLength");
			this.m_BitsPerSample = GetInitialValue("tiff:BitsPerSample", "seq Integer");
			NotifyPropertyChanged("BitsPerSample");
			this.m_Compression = GetInitialValue("tiff:Compression", "Closed Choice");
			NotifyPropertyChanged("Compression");
			this.m_PhotometricInterpretation = GetInitialValue("tiff:PhotometricInterpretation", "Closed Choice");
			NotifyPropertyChanged("PhotometricInterpretation");
			this.m_Orientation = GetInitialValue("tiff:Orientation", "Closed Choice");
			NotifyPropertyChanged("Orientation");
			this.m_SamplesPerPixel = GetInitialValue("tiff:SamplesPerPixel", "Integer");
			NotifyPropertyChanged("SamplesPerPixel");
			this.m_PlanarConfiguration = GetInitialValue("tiff:PlanarConfiguration", "Closed Choice");
			NotifyPropertyChanged("PlanarConfiguration");
			this.m_YCbCrSubSampling = GetInitialValue("tiff:YCbCrSubSampling", "Closed Choice");
			NotifyPropertyChanged("YCbCrSubSampling");
			this.m_YCbCrPositioning = GetInitialValue("tiff:YCbCrPositioning", "Closed Choice");
			NotifyPropertyChanged("YCbCrPositioning");
			this.m_XResolution = GetInitialValue("tiff:XResolution", "Rational");
			NotifyPropertyChanged("XResolution");
			this.m_YResolution = GetInitialValue("tiff:YResolution", "Rational");
			NotifyPropertyChanged("YResolution");
			this.m_ResolutionUnit = GetInitialValue("tiff:ResolutionUnit", "Closed Choice");
			NotifyPropertyChanged("ResolutionUnit");
			this.m_TransferFunction = GetInitialValue("tiff:TransferFunction", "seq Integer");
			NotifyPropertyChanged("TransferFunction");
			this.m_WhitePoint = GetInitialValue("tiff:WhitePoint", "seq Rational");
			NotifyPropertyChanged("WhitePoint");
			this.m_PrimaryChromaticities = GetInitialValue("tiff:PrimaryChromaticities", "seq Rational");
			NotifyPropertyChanged("PrimaryChromaticities");
			this.m_YCbCrCoefficients = GetInitialValue("tiff:YCbCrCoefficients", "seq Rational");
			NotifyPropertyChanged("YCbCrCoefficients");
			this.m_ReferenceBlackWhite = GetInitialValue("tiff:ReferenceBlackWhite", "seq Rational");
			NotifyPropertyChanged("ReferenceBlackWhite");
			this.m_DateTime = GetInitialValue("tiff:DateTime", "Date");
			NotifyPropertyChanged("DateTime");
			this.m_ImageDescription = GetInitialValue("tiff:ImageDescription", "Lang Alt");
			NotifyPropertyChanged("ImageDescription");
			this.m_Make = GetInitialValue("tiff:Make", "ProperName");
			NotifyPropertyChanged("Make");
			this.m_Model = GetInitialValue("tiff:Model", "ProperName");
			NotifyPropertyChanged("Model");
			this.m_Software = GetInitialValue("tiff:Software", "AgentName");
			NotifyPropertyChanged("Software");
			this.m_Artist = GetInitialValue("tiff:Artist", "ProperName");
			NotifyPropertyChanged("Artist");
			this.m_Copyright = GetInitialValue("tiff:Copyright", "Lang Alt");
			NotifyPropertyChanged("Copyright");
		}
		#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