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

ExifTagCollection - An EXIF metadata extraction library

By , 24 Jun 2008
 

Introduction

This library is inspired by the ExifExtractor class by Asim Goheer. The problem with ExifExtractor was that it does not support some tags defined in the EXIF 2.2 standard, like tags related to GPS data, so I decided to modify it, but, eventually, decided to write it from scratch, though I reused some of Asim's code..

The ExifTagsCollection is based on IEnumerable<T>, and holds a collection of ExifTag classes that encapsulates an EXIF tag.

The ExifTag class holds the field name, description, ID, and the value for the given tag. A couple of convenient classes have been added:

  • Rational - for signed rational values
  • URational - for unsigned rational values
  • GPSRational - for GPS 24 bit data

Using the code

Using the code is pretty straightforward. Here is an example of listing all the tags in the console:

// See other constructors, for creating ExifTagCollection with Image instance, etc.
ExifTagCollection exif = new ExifTagCollection(@"c:\somefile.jpg");

foreach (ExifTag tag in exif)
    Console.Out.WriteLine(tag);

Another example for getting a specific tag by ID:

ExifTagCollection exif = new ExifTagCollection(@"c:\somefile.jpg");

ExifTag tag = exif[2];
Console.Out.WriteLine(tag);
//OUTPUT: Latitude (GPSLatitude) = 22° 47' 35,35"

Supported EXIF fields:

  • ImageWidth - Image width
  • ImageHeight - Image height
  • GPSVersionID - GPS tag version
  • GPSAltitudeRef - Altitude reference
  • StripOffsets - Image data location
  • RowsPerStrip - Number of rows per strip
  • StripByteCounts - Bytes per compressed strip
  • PixelXDimension - Valid image width
  • PixelYDimension - Valid image height
  • BitsPerSample - Number of bits per component
  • Compression - Compression scheme
  • PhotometricInterpretation - Pixel composition
  • Orientation - Orientation of image
  • SamplesPerPixel - Number of components
  • PlanarConfiguration - Image data arrangement
  • YCbCrSubSampling - Sub-sampling ratio of Y to C
  • YCbCrPositioning - Y and C positioning
  • ResolutionUnit - Unit of X and Y resolution
  • TransferFunction - Transfer function
  • ColorSpace - Color space information
  • ExposureProgram - Exposure program
  • ISOSpeedRatings - ISO speed rating
  • MeteringMode - Metering mode
  • LightSource - Light source
  • Flash - Flash
  • SubjectArea - Subject area
  • FocalPlaneResolutionUnit - Focal plane resolution unit
  • SubjectLocation - Subject location
  • SensingMethod - Sensing method
  • CustomRendered - Custom image processing
  • ExposureMode - Exposure mode
  • WhiteBalance - White balance
  • FocalLengthIn35mmFilm - Focal length in 35 mm film
  • SceneCaptureType - Scene capture type
  • Contrast - Contrast
  • Saturation - Saturation
  • Sharpness - Sharpness
  • SubjectDistanceRange - Subject distance range
  • GPSDifferential - GPS differential correction
  • ShutterSpeedValue - Shutter speed
  • BrightnessValue - Brightness
  • ExposureBiasValue - Exposure bias
  • JPEGInterchangeFormat - Offset to JPEG SOI
  • JPEGInterchangeFormatLength - Bytes of JPEG data
  • XResolution - Image resolution in width direction
  • YResolution - Image resolution in height direction
  • WhitePoint - White point chromaticity
  • PrimaryChromaticities - Chromaticities of primaries
  • YCbCrCoefficients - Color space transformation matrix coefficients
  • ReferenceBlackWhite - Pair of black and white reference values
  • CompressedBitsPerPixel - Image compression mode
  • ExposureTime - Exposure time
  • FNumber - F number
  • ApertureValue - Aperture
  • MaxApertureValue - Maximum lens aperture
  • SubjectDistance - Subject distance
  • FocalLength - Lens focal length
  • FlashEnergy - Flash energy
  • FocalPlaneXResolution - Focal plane X resolution
  • FocalPlaneYResolution - Focal plane Y resolution
  • ExposureIndex - Exposure index
  • DigitalZoomRatio - Digital zoom ratio
  • GainControl - Gain control
  • GPSLatitude - Latitude
  • GPSLongitude - Longitude
  • GPSAltitude - Altitude
  • GPSTimeStamp - GPS time (atomic clock)
  • GPSDOP - Measurement precision
  • GPSSpeed - Speed of GPS receiver
  • GPSTrack - Direction of movement
  • GPSImgDirection - Direction of image
  • GPSDestLatitude - Latitude of destination
  • GPSDestLongitude - Longitude of destination
  • GPSDestBearing - Bearing of destination
  • GPSDestDistance - Distance to destination
  • DateTime - File change date and time
  • ImageDescription - Image title
  • Make - Image input equipment manufacturer
  • Model - Image input equipment model
  • Software - Software used
  • Artist - Person who created the image
  • Copyright - Copyright holder
  • RelatedSoundFile - Related audio file
  • DateTimeOriginal - Date and time of original data generation
  • DateTimeDigitized - Date and time of digital data generation
  • SubSecTime - DateTime subseconds
  • SubSecTimeOriginal - DateTimeOriginal subseconds
  • SubSecTimeDigitized - DateTimeDigitized subseconds
  • ImageUniqueID - Unique image ID
  • SpectralSensitivity - Spectral sensitivity
  • GPSLatitudeRef - North or South Latitude
  • GPSLongitudeRef - East or West Longitude
  • GPSSatellites - GPS satellites used for measurement
  • GPSStatus - GPS receiver status
  • GPSMeasureMode - GPS measurement mode
  • GPSSpeedRef - Speed unit
  • GPSTrackRef - Reference for direction of movement
  • GPSImgDirectionRef - Reference for direction of image
  • GPSMapDatum - Geodetic survey data used
  • GPSDestLatitudeRef - Reference for latitude of destination
  • GPSDestLongitudeRef - Reference for longitude of destination
  • GPSDestBearingRef - Reference for bearing of destination
  • GPSDestDistanceRef - Reference for distance to destination
  • GPSDateStamp - GPS date
  • OECF - Optoelectric conversion factor
  • SpatialFrequencyResponse - Spatial frequency response
  • FileSource - File source
  • SceneType - Scene type
  • CFAPattern - CFA pattern
  • DeviceSettingDescription - Device settings description
  • ExifVersion - EXIF version
  • FlashpixVersion - Supported Flashpix version
  • ComponentsConfiguration - Meaning of each component
  • MakerNote - Manufacturer notes
  • UserComment - User comments
  • GPSProcessingMethod - Name of GPS processing method
  • GPSAreaInformation - Name of GPS area

History

  • Initial release.

License

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

About the Author

Lev Danielyan
Software Developer (Senior) Virage Logic Corporation
Armenia Armenia
Member
I'm a developer focusing on Quality Assurance at the Virage Logic Corporation.
My main responsibilities include the development and maintenance of an environment for automated quality assurance of the Verilog IP provided by our company.

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

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberbbcdk16 May '11 - 11:23 
I'm using this library in a freeware project and it works perfectly. Thanks!
QuestionSupport DNG format?memberMember 767189814 Feb '11 - 4:05 
This is a nice and useful library. I can handle all my jpeg images with it. But it would be very nice if i can handle my dng images too. Now I get some infos about make, model and software, but no infos about exposure time, F number or focal length. The shown image width and height seems to be those of the embedded thumbnail.
 
Is it hard for you to get the infos out of a raw image?
 
Thomas
GeneralMy vote of 4memberinksmithy22 Jan '11 - 2:08 
Great work, code worked perfectly, thanks very much!
GeneralMy vote of 4memberSlacker00720 Jan '11 - 0:25 
Thanks for sharing. Cool.
GeneralExcellent code ! Works perfectly !memberDan Clark17 Feb '10 - 12:01 
Great job !


Very cool website !


@{${$dan}{c}{clark}}[1]


GeneralPretty coolmemberMember 292415727 Sep '09 - 10:04 
I used it to add exif data to the photos of my web gallery.
Thank you.
Stefan
Generaledit exif valuememberUnruled Boy20 Apr '09 - 19:55 
you could set the PropertyItem.Value, then save the image.
 
Regards,
unruledboy_at_gmail_dot_com
http://www.xnlab.com

GeneralRe: edit exif valuememberglenneroo27 Nov '10 - 15:14 
Your code works, but unfortunately it isn't a lossless operation i.e. you will lose some data by saving it back again (as well as it taking some time to save the data).
Jokehello!:)memberdiligentpig3 Nov '08 - 18:20 
I'm making a asp.net project where I want the user uploads a jpeg file and process it by adding GPS info. to its EXIF tag and let the user download it.
Whatever,I tried using the EXIFExtractor to read exif info and use the settag() mathod such way to add GPS to exif:
 
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(strfilename);
Goheer.EXIF.EXIFextractor er = new Goheer.EXIF.EXIFextractor(ref bmp, "");
er.setTag(0x0, "2");//gps ver
er.setTag(0x1, "N");//lat. ref
er.setTag(0x2, "108.11223344");//latitude
er.setTag(0x3, "E");//long. ref
er.setTag(0x4, "34.11223344");//longitude
er.setTag(0x7, "0/0");//gpstime
bmp.Save(strnewfilename);
 
then I use EXIFExtractor to read the new exif,it seems worked.I can read the GPS info from the processed file.
BUT,when I used other software which can read GPS info and locate the photo on google map to read the processed file,it failed, the GPS info in the processed file can't be read out....
 
I'm wondering if I can't using the EXIFExtracor.settag() method to simply add a string varible such as "108.11223344" to make my idea work?
 
Any suggestions?
 
I've download your code and will try it later,hope it helped.
 
Thanks very much whatever Smile | :)
GeneralRe: hello!:)memberLev Danielyan4 Nov '08 - 1:47 
Hi,
 
Well, actually the ExifExtractor doesn't have SetTag method (yet, I still don't have enough time to get back to the code and implement the tag writing code).
 
I haven't checked Asim Goheer code for SetTag method (I assume from the code, you are using his code for setting the tags' values), so you better contact him for the details, or check his code to see how the values are being set.
 
All I can say is that I tested the GPS tag extraction on various images (including some images that actually work with online services, like google, and standalone applications, like ACDSee or XnView), and everything worked just fine. Smile | :)
 
Lev

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 25 Jun 2008
Article Copyright 2008 by Lev Danielyan
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid