Click here to Skip to main content
Click here to Skip to main content

ExifLib - A Fast Exif Data Extractor for .NET 2.0+

By , 8 Apr 2013
 
Exif Lib - test application

Introduction

ExifLib simply reads Exif tags (i.e., camera model, GPS data, date picture taken, shutter speed etc.) from JPEG files, without the overhead introduced by using the GDI+ classes located in System.Drawing.Imaging, and with less lines of code for the developer.

Background

I've been using a simple command line application to move my photos into subdirectories based on the date on which they were created. As with all other .NET Exif implementations I've seen, I was using the PropertyItem class located in System.Drawing.Imaging. While this does the job, I often found myself processing thousands of images at a time, and the .NET classes were just too slow for the job. ExifLib goes back to the JPEG/TIFF standard itself, and only reads the essentials, using little more than the file input classes in System.IO.

Using the Code

ExifLib is very simple, with only one class and one enum in the namespace. Just add a reference to ExifLib.dll, and you're good to go! An example follows:

using ExifLib;
...
...
...
// Instantiate the reader
ExifReader reader = new ExifReader(@"C:\temp\testImage.jpg");

// Extract the tag data using the ExifTags enumeration
DateTime datePictureTaken;
if (reader.GetTagValue<DateTime>(ExifTags.DateTimeDigitized, 
                                    out datePictureTaken))
{
    // Do whatever is required with the extracted information
    MessageBox.Show(this, string.Format("The picture was taken on {0}", 
       datePictureTaken), "Image information", MessageBoxButtons.OK);
}

Points of Interest

Something strange that I learned while writing this library is that while JPEG stipulates "Big Endian" encoding (i.e., numbers read from left to right), the TIFF standard allows Big or Little Endian encoding. Since the Exif tags are encoded using TIFF encoding, often the JPEG will be read using "Big Endian" encoding until the TIFF section is reached, at which point the encoding reverses and the rest of the document is read using "Little Endian" encoding.

During coding, I realised from a comment on the ExifWorks CodeProject article that it's possible to increase performance when using System.Drawing.Image by setting the constructor's validateImageData parameter to false. However, even when using this enhancement, ExifLib still performs 50% faster, possibly because it does not read the tag values until they're requested. I have also noticed that ExifLib performs similarly with small (<1MP) images, but scales better when loading larger images. The screenshot at the top of this page was produced using a 12MP image.

History

Version 1.1

  • Array extraction has been added, thanks to a comment from Justin Carasick. This is used in various fields, including GPS coordinates and Exif versioning. The previous version of ExifLib would only return the first element from an array.

Version 1.2

  • Fixed bug when retrieving data for fields shorter than 4 bytes, thanks to a comment from bartsy. The previous version of ExifLib would lose important data from these fields when processing big-endian encoded files.
  • Updated the project to Visual Studio 2010, refactored a little of the code. The project is still .NET 2.0+.

Version 1.3

  • Added the ability to extract JPEG encoded thumbnails from images, thanks to a comment from StyrianOak. Note that uncompressed (i.e. TIFF) encoded thumbnails are not supported, but since any camera which supports the DCF standard will produce JPEG thumbnails, this is a minor limitation.

Version 1.4

  • Added a constructor overload to allow reading of JPEG data from any seekable stream
  • Modified code to allow compiling for Windows Phone and Silverlight. The NuGet package now includes Windows Phone and Silverlight DLLs.
  • Improved support for null DateTime values thanks to comments from schurig and BrandonOrding
  • undefined Exif fields are now returned as byte[] instead of uint[]

NuGet Release

ExifLib is now available on nuget! Simply install from the Visual Studio Package Manager Console using Install-Package ExifLib.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Simon McKenzie
Software Developer BreastScreen Victoria
Australia Australia
Member

Simon McKenzie has been working as a developer for 9 years, primarily in .NET and Java, with interests in imaging and GIS, particularly on mobile platforms. He is the author of the award winning MapSnap GPS, a moving map application for Windows Phone. He's also the author of the popular (free) high-speed ExifLib EXIF extractor for .NET.


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionModify EXIF datamemberMember 100309438 May '13 - 2:22 
AnswerRe: Modify EXIF datamemberSimon McKenzie8 May '13 - 13:44 
GeneralRe: Modify EXIF datamemberMember 100309438 May '13 - 21:32 
GeneralRe: Modify EXIF datamemberSimon McKenzie9 May '13 - 13:44 
GeneralRe: Modify EXIF datamemberMember 1003094313 May '13 - 4:55 
GeneralRe: Modify EXIF datamemberSimon McKenzie13 May '13 - 15:25 
GeneralRe: Modify EXIF datamemberMember 1003094313 May '13 - 21:17 
QuestionGet OrientationmemberMember 100309435 May '13 - 22:17 
AnswerRe: Get OrientationmemberSimon McKenzie6 May '13 - 1:06 
GeneralRe: Get OrientationmemberMember 100309436 May '13 - 1:17 
GeneralRe: Get OrientationmemberSimon McKenzie6 May '13 - 1:37 
GeneralRe: Get OrientationmemberMember 100309436 May '13 - 3:09 
GeneralMy vote of 5memberdamianom13 Apr '13 - 0:42 
QuestionNeed a way to tell if ANY EXIF data is presentmemberMikeStammer12 Apr '13 - 9:43 
AnswerRe: Need a way to tell if ANY EXIF data is presentmemberSimon McKenzie12 Apr '13 - 17:56 
QuestionExcellent Stuff - Use this in SharePointmemberMartian Keeper11 Apr '13 - 23:12 
QuestionSource code repository?membermauricitoia9 Apr '13 - 6:43 
AnswerRe: Source code repository?memberSimon McKenzie9 Apr '13 - 12:32 
GeneralMy vote of 5memberKim Togo9 Apr '13 - 0:37 
BugThe ExifLib Can't work on Windows Phone 8memberMember 83033937 Apr '13 - 21:33 
GeneralRe: The ExifLib Can't work on Windows Phone 8memberSimon McKenzie7 Apr '13 - 22:16 
GeneralRe: The ExifLib Can't work on Windows Phone 8memberMember 83033938 Apr '13 - 2:18 
GeneralRe: The ExifLib Can't work on Windows Phone 8 [modified]memberSimon McKenzie8 Apr '13 - 13:06 
QuestionJust what I needed for file renamingmemberyggyking7 Apr '13 - 9:17 
AnswerRe: Just what I needed for file renamingmemberSimon McKenzie7 Apr '13 - 13:08 
QuestionAn issue with iOS photos.memberJohn Benner30 Mar '13 - 4:00 
AnswerRe: An issue with iOS photos.memberSimon McKenzie1 Apr '13 - 12:29 
GeneralOnce - al ong time ago - I also did this in a similar way...memberAndyHo28 Mar '13 - 6:42 
GeneralLearn from youmemberlovevb12316 Mar '13 - 5:47 
QuestionInterface for mockingmemberMartinWager6 Feb '13 - 22:57 
AnswerRe: Interface for mockingmemberSimon McKenzie7 Feb '13 - 11:57 
QuestionParse problemmemberschurig31 Jan '13 - 22:53 
AnswerRe: Parse problemmemberBrandonOrding7 Feb '13 - 15:38 
GeneralRe: Parse problemmemberSimon McKenzie7 Feb '13 - 15:51 
AnswerRe: Parse problemmemberSimon McKenzie7 Feb '13 - 15:46 
BugTweaks needed to make this work with Blackberry imagesmemberstevehiner10 Dec '12 - 12:39 
GeneralRe: Tweaks needed to make this work with Blackberry imagesmemberSimon McKenzie10 Dec '12 - 12:47 
GeneralRe: Tweaks needed to make this work with Blackberry imagesmemberstevehiner10 Dec '12 - 12:51 
GeneralRe: Tweaks needed to make this work with Blackberry imagesmemberSimon McKenzie10 Dec '12 - 19:10 
GeneralRe: Tweaks needed to make this work with Blackberry imagesmemberstevehiner11 Dec '12 - 6:23 
GeneralRe: Tweaks needed to make this work with Blackberry imagesmemberSimon McKenzie11 Dec '12 - 11:14 
QuestionWrite SupportmemberRadarRambox30 Nov '12 - 2:16 
AnswerRe: Write SupportmemberSimon McKenzie1 Dec '12 - 10:47 
AnswerRe: Write SupportmemberRadarRambox2 Dec '12 - 19:52 
GeneralMy vote of 5memberreisenklaus14 Nov '12 - 11:08 
GeneralRe: My vote of 5memberSimon McKenzie14 Nov '12 - 13:56 
GeneralRe: My vote of 5memberSimon McKenzie14 Nov '12 - 18:05 
GeneralRe: My vote of 5memberreisenklaus15 Nov '12 - 9:30 
Questionweb - File is not a valid JPEG [modified]membernanonerd12 Nov '12 - 7:06 
AnswerRe: web - File is not a valid JPEGmembernanonerd12 Nov '12 - 10:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 9 Apr 2013
Article Copyright 2009 by Simon McKenzie
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid