Skip to content

Instantly share code, notes, and snippets.

@bcalloway
Created January 4, 2012 03:10
Show Gist options
  • Save bcalloway/1558288 to your computer and use it in GitHub Desktop.
Save bcalloway/1558288 to your computer and use it in GitHub Desktop.
C# EXIF Data
//Property Item 36867 corresponds to the Date Taken
public static readonly int DateItem = 36867;
static public DateTime? GetDateTaken(Image targetImg) {
DateTime? created;
try
{
PropertyItem propItem = targetImg.GetPropertyItem(DateItem);
//Convert date taken metadata to a DateTime object
string sdate = Encoding.UTF8.GetString(propItem.Value).Trim();
string secondhalf = sdate.Substring(sdate.IndexOf(" "), (sdate.Length - sdate.IndexOf(" ")));
string firsthalf = sdate.Substring(0, 10);
firsthalf = firsthalf.Replace(":", "-");
sdate = firsthalf + secondhalf;
created = DateTime.Parse(sdate);
}
catch (Exception e)
{
// No EXIF data
created = null;
}
return created;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment