8

I've searched on this topic but the only suitable threads I can find are dated 2008 hence my new question.

I'm looking at developing a program using C# .Net 4.0 language. The aim of my program will be to extract EXIF information from jpegs (Manufacturer, Model, Geolocation info etc...) and then populate this into a MySql / Sql server DB.

Can anybody recommend any good libraries that may be suitable for this project? I would be looking for camera serial numbers too (I know this varies from manufacturer to manufacturer) but if anybody knows of any existing libraries that address this, it'd be most helpful.

Thanks and enjoy the weekend

thefragileomen
  • 1,537
  • 8
  • 24
  • 40
  • are you looking for free libraries or commercial ? – Yahia Aug 19 '11 at 22:25
  • I'm looking for both. It all depends on the costs of the commercial ones but if you can recommend any, I'm happy to take a look at them. If there are free ones that do just a good job, then I'd prefer them :) – thefragileomen Aug 19 '11 at 22:27
  • I didn't try any free ones... but take a look at LeadTools or GdPicutre... esp. the camera specific information will be a nightmare since that changes very often so you need to update often... – Yahia Aug 19 '11 at 22:48
  • See [this](http://stackoverflow.com/questions/2169444/how-can-i-read-the-exif-data-from-an-image-taken-with-an-apple-iphone) and [this](http://stackoverflow.com/questions/58649/how-to-get-the-exif-data-from-a-file-using-c). – adrianbanks Aug 19 '11 at 23:00
  • EXIF hasn't changed since 2008. What ever was relevant back then is still relevant now. – Hans Passant Aug 20 '11 at 09:00
  • http://stackoverflow.com/help/on-topic "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Felix K. Aug 09 '15 at 21:33

3 Answers3

10

The metadata-extractor project has been alive and well since 2002 for Java, and is now available for .NET 3.5 and above. There is also a PCL version.

  • Open source (Apache 2.0)
  • Heavily tested and widely used
  • Supports many image types (JPEG, TIFF, PNG, WebP, GIF, BMP, ICO, PCX...)
  • Supports many metadata types (Exif, IPTC, XMP, JFIF, ...)
  • Supports many manufacturer-specific fields (Canon, Nikon, ...)
  • Very fast (fully processes ~400 images totalling 1.33GB in ~3 seconds) with low memory consumption

It's available via NuGet or GitHub.

Sample usage:

IEnumerable<Directory> directories = ImageMetadataReader.ReadMetadata(path);

foreach (var directory in directories)
foreach (var tag in directory.Tags)
    Console.WriteLine($"{directory.Name} - {tag.TagName} = {tag.Description}");

(Disclosure: I maintain this library)

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
  • Not what the OP asked for since it is .NET 4.5+ only – mfeineis Aug 07 '15 at 08:40
  • However it *is* a nice library and maybe you could provide a build for us poor souls still stuck with .NET4.0? That'd be great! I tried to change the target framework in VS2015 myself but it seems that you're depending on a lot of .NET4.5 stuff... – mfeineis Aug 07 '15 at 08:51
  • 1
    @vanhelgen, thanks for the feedback! I'll add support for earlier versions of .NET too. See [this new issue](https://github.com/drewnoakes/metadata-extractor-dotnet/issues/22). – Drew Noakes Aug 08 '15 at 16:32
  • 3
    @vanhelgen, done. Version 1.1.0 is up on NuGet and supports both .NET 3.5 and 4.5. It'd be great if you could test it out and let me know how you get on. – Drew Noakes Aug 09 '15 at 21:23
  • Thats great, thank you! – mfeineis Aug 10 '15 at 07:53
  • 1
    got v1.1.0 working in my .NET4.0 project without any issues. Thanks again! – mfeineis Aug 12 '15 at 11:56
  • @vanhelgen, great news. Thanks for confirming it's working for you :) – Drew Noakes Aug 12 '15 at 12:24
  • Does this library work on file headers or require loading the image data? I need it to extract metadata from large collection of huge images, hence speed is important... – Libor Feb 16 '16 at 11:56
  • @Libor, it doesn't decode any image data and navigates through the file in an optimal way. It's very fast and is well suited to large volumes of image data. Let me know how you get on. – Drew Noakes Feb 16 '16 at 12:11
  • 1
    @DrewNoakes Thanks, you saved me some time researching it. I will definitely give it a try. – Libor Feb 17 '16 at 16:57
6

This CodeProject article was written just last month, and its API is a big improvement over some of the other .NET EXIF readers:

http://www.codeproject.com/Articles/36342/ExifLib-A-Fast-Exif-Data-Extractor-for-NET-2-0

It's also available over Nuget, and is licensed under the CPOL.

Charlie
  • 15,069
  • 3
  • 64
  • 70
4

For basic EXIF information(manufacturer, camera model, time, aperture, etc.), I would look at the System.Drawing.Image class - in particular the PropertiesItems collection.

There are disadvantages to this class. It requires loading the entire image into memory before retrieving the EXIF info (i.e. it is somewhat slow). It also does not handle all of the vendor specific fields that aren't uniform from camera to camera.

Image.PropertyItems

MSDN: Reading Image Metadata

PropertyItem.Id

I have used it with great success to collect information about my photo collection (tens of thousands of photos taken with a dozen different digital cameras of various makes and models).

Jason Moore
  • 3,294
  • 15
  • 18
  • 6
    I too have used this for EXIF info and found it works well. Did you know that there is a built-in way to skip the loading of the image and just get the metadata? Massive speed improvement! You must use `Image.FromFile(Stream, false, false)`... See more info here : http://msdn.microsoft.com/en-us/library/21zw9ah6.aspx – Scott Rippey Sep 15 '11 at 17:20
  • 1
    If speed is important, you could also compile exifLib for .NET 4.0: http://www.codeproject.com/Articles/36342/ExifLib-A-Fast-Exif-Data-Extractor-for-NET-2-0. It's faster than Image.FromFile(stream, false, false) when reading single tags. If you need to read a LOT of tags, the built in framework libraries may be faster. – Simon MᶜKenzie May 09 '12 at 00:16
  • There's an interesting comment on the exifLib project page: "it's possible to increase performance when using System.Drawing.Image by setting the constructor's validateImageData parameter to false." – Yogi May 23 '20 at 14:00