Created
January 4, 2012 03:10
-
-
Save bcalloway/1558288 to your computer and use it in GitHub Desktop.
C# EXIF Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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