Date Taken EXIF Data for a Picture


/ Published in: C#
Save to your folder(s)

Reads the EXIF Data to find the actual original taken date. This is available on most camera's.


Copy this code and paste it in your HTML
  1. /// <summary>
  2. /// Returns the EXIF Image Data of the Date Taken.
  3. /// </summary>
  4. /// <param name="getImage">Image (If based on a file use Image.FromFile(f);)</param>
  5. /// <returns>Date Taken or Null if Unavailable</returns>
  6. public static DateTime? DateTaken(Image getImage)
  7. {
  8. int DateTakenValue = 0x9003; //36867;
  9.  
  10. if (!getImage.PropertyIdList.Contains(DateTakenValue))
  11. return null;
  12.  
  13. string dateTakenTag = System.Text.Encoding.ASCII.GetString(getImage.GetPropertyItem(DateTakenValue).Value);
  14. string[] parts = dateTakenTag.Split(':', ' ');
  15. int year = int.Parse(parts[0]);
  16. int month = int.Parse(parts[1]);
  17. int day = int.Parse(parts[2]);
  18. int hour = int.Parse(parts[3]);
  19. int minute = int.Parse(parts[4]);
  20. int second = int.Parse(parts[5]);
  21.  
  22. return new DateTime(year, month, day, hour, minute, second);
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.