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

Retrieving EXIF information of an image in .NET 3.0

, 2 Jul 2007
Rate this:
Please Sign up or sign in to vote.
How to retrieve EXIF information of an image in .NET 3.0.

Screenshot - Article_Image.jpg

Introduction

When we talk about digital photography, one of the things which comes to mind is EXIF info. What is it? EXIF is the short for "Exchangeable Image File". This is a standard for storing interchangeable information in digital photography image files using JPEG compression. Most of the new digital cameras use the EXIF annotation, and store information on the image such as shutter speed, exposure, compensation, F number, metering system, ISO number, Date Time etc. This piece of code explains how to retrieve the EXIF information from an image using .NET 3.0.

Using the code

To use the code, you should have the following items installed on your machine:

  • .NET Framework 3.0
  • WPF Patch release for Visual Studio 2005

Using the code is pretty simple, and can be downloaded from above. In the code, the constructor of class ExifMetaInfo accepts the URI of an image as a parameter, and creates an object of type BitmapFrame (BitmapFrame is a new class library available under "System.Windows.Media.Imaging" of .NET 3.0). Once the BitmapFrame object is created, we can get the meta-data information of the image using the MetaData property of BitmapFrame. We can type cast the MetaData property to the BitmapMetadata class, which is again a new class in .NET 3.0 under "System.Windows.Media.Imaging". Now, it's a matter of passing the right parameters to the "BitmapMetadata" object to get the EXIF information. Following is a list of parameters which we may pass to get the appropriate EXIF information:

Width /app1/ifd/exif/subifd:{uint=40962}
Height /app1/ifd/exif/subifd:{uint=40963}
EquipmentManufacturer /app1/ifd/exif:{uint=271}
CameraModel /app1/ifd/exif:{uint=272}
CreationSoftware /app1/ifd/exif:{uint=305}
ColorRepresentation /app1/ifd/exif/subifd:{uint=40961}")
ExposureTime /app1/ifd/exif/subifd:{uint=33434}
LensAperture /app1/ifd/exif/subifd:{uint=33437}

.....and many more.

The section below shows a snap of the constructor of the ExifMetaInfo class, which accepts a URI as a parameter and creates an object of type BitmapFrame:

public ExifMetaInfo(Uri imageUri)
{
    BitmapFrame bFrame = BitmapFrame.Create(imageUri, 
                BitmapCreateOptions.DelayCreation, 
                BitmapCacheOption.None);
    _metaInfo = (BitmapMetadata)bFrame.Metadata;
}

Once we are done with the creation of the object, the next thing to do is to fetch the values. In the given class, all the EXIF info is being retrieved through properties. The code below shows the retrieval of the Width property of the image:

public uint? Width
{
    get
    {
        object obj = GetMetaInfo("/app1/ifd/exif/subifd:{uint=40962}");
        if (obj == null)
        {
            return null;
        }
        else
        {
            if (obj.GetType() == typeof(UInt32))
                return (uint)obj;
            else
                return Convert.ToUInt32(obj);
        }
    }
}

private object GetMetaInfo(string infoQuery)
{
    if (_metaInfo.ContainsQuery(infoQuery))
        return _metaInfo.GetQuery(infoQuery);
    else
        return null;
}

Points of interest

Please note that all JPG images may not have EXIF info available. You may modify the code of the ExifMetaInfo class to give a user friendly message when no information is available.

History

Nothing available at present.

License

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

About the Author

No Biography provided

Comments and Discussions

 
Generalgps information Pinmembercookie_biscuit28-Mar-09 15:17 
GeneralRe: gps information PinmemberFelipe Ceotto17-Apr-09 0:44 
Generaledit the exif information using .net 2.0 Pinmembernallamani198317-Mar-09 21:32 
GeneralASP.NET 3.0 PinmemberRoelAlblas12-Jul-08 4:45 
AnswerRe: ASP.NET 3.0 Pinmemberuttam1914-Nov-08 23:54 
GeneralMetadata 272 may contain string[] PinmemberCodeChampion22-Apr-08 4:18 
QuestionExif GetQuery strings PinmemberGreenKnight12-Sep-07 3:51 
GeneralRe: Exif GetQuery strings PinmemberFaulstiR7-Dec-07 17:46 
AnswerRe: Exif GetQuery strings PinmemberFaulstiR7-Dec-07 18:07 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 2 Jul 2007
Article Copyright 2007 by Puru Adhikari
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid