Extracting EXIF metadata from JPG images

Drew Noakes has written a great EXIF metadata extractor for JPG images in Java which was ported to C# by Ferret Renaud.  This allows you to pull out the EXIF data like camera model & date taken.  You can also access the width & height of the image without loading it into a .NET image object.

Here is some sample code on how to use the library:

   1:  FileInfo f = new FileInfo(file);
   2:  var metadata = com.drew.imaging.jpg.JpegMetadataReader.ReadMetadata(f);
   3:  var exif = metadata.GetDirectory(typeof(com.drew.metadata.exif.ExifDirectory).ToString()) as ExifDirectory;
   4:  var jpg = metadata.GetDirectory(typeof(com.drew.metadata.jpeg.JpegDirectory).ToString()) as JpegDirectory;
   5:  ImageModel model = new ImageModel() { 
   6:      path = f.Name, 
   7:      height = jpg.GetImageHeight(),
   8:      width = jpg.GetImageWidth(),
   9:      taken = exif.ContainsTag(ExifDirectory.TAG_DATETIME_ORIGINAL) ? (DateTime?) exif.GetDate(ExifDirectory.TAG_DATETIME_ORIGINAL) : null,
  10:      maker = exif.GetString(ExifDirectory.TAG_MAKE),
  11:      model = exif.GetString(ExifDirectory.TAG_MODEL)
  12:  };


1 Comment

Comments have been disabled for this content.