views:

10716

answers:

7

Hi, I would like to write a small program in C# which goes through my jpeg photos and, for example, sorts them into dated folders (using MY dating conventions, dammit...).

Does anyone know a relatively easy way to get at the EXIF data such as Date And Time or Exposure programatically? Thanks!

+3  A: 

Here is a good library for it. You can even get the source code to have a look inside.

Biri
A: 

Getting EXIF data from a JPEG image involves :

  1. Seeking to the JPEG markers which mentions the beginning of the EXIF data,. e.g. normally oxFFE1 is the marker inserted while encoding EXIF data, which is a APPlication segment, where EXIF data goes.
  2. Parse all the data from say 0xFFE1 to 0xFFE2 . This data would be stream of bytes, in the JPEG encoded file.
  3. ASCII equivalent of these bytes would contain various information related to Image Date, Camera Model Name, Exposure etc...

-AD

goldenmean
+3  A: 

Image class has PropertyItems and PropertyIdList properties. You can use them.

idursun
It seems it's read-only, so I cannot add any on the new Image...
TigrouMeow
Use the Image.SetPropertyItem(PropertyItem) function on the new image.
Morten Christiansen
+3  A: 

Check out this metadata extractor. It is written in Java but has also been ported to C#. I have used the Java version to write a small utility to rename my jpeg files based on the date and model tags. Very easy to use.

Dave Griffiths
+2  A: 

Link to similar SO question: What is the best EXIF library for .Net?

Jakub Šturc
+3  A: 

Here is a link to another similar SO question, which has an answer pointing to this good article on "Reading, writing and photo metadata" in .Net.

Joel in Gö
+4  A: 

As suggested, you can use some 3rd party library, or do it manually (which is not that much work), but the simplest and the most flexible is to perhaps use the built-in functionality in .NET. For more see:

I say "it’s the most flexible" because .NET does not try to interpret or coalesce the data in any way. For each EXIF you basically get an array of bytes. This may be good or bad depending on how much control you actually want.

Also, I should point out that the property list does not in fact directly correspond to the EXIF values. EXIF itself is stored in multiple tables with overlapping ID’s, but .NET puts everything in one list and redefines ID’s of some items. But as long as you don’t care about the precise EXIF ID’s, you should be fine with the .NET mapping.

Jan Zich