Click here to Skip to main content
15,923,168 members
Articles / Multimedia / GDI+
Article

A library to simplify access to image metadata

Rate me:
Please Sign up or sign in to vote.
4.84/5 (32 votes)
3 Aug 20044 min read 284.1K   10.1K   115   48
A library to simplify access to image metadata.

Introduction

Several image file formats enable you to store metadata along with an image. Metadata is information about an image, for example, title, width, camera model, and artist. Microsoft Windows GDI+ provides a uniform way of storing and retrieving metadata from image files in the Tagged Image File Format (TIFF), JPEG, Portable Network Graphics (PNG), and Exchangeable Image File (EXIF) formats. In GDI+, a piece of metadata is called a property item, and an individual property item is identified by a numerical constant called a property tag.

In .NET Framework, you can store and retrieve metadata by calling the SetPropertyItem and GetPropertyItem methods of the Image class, and you don't have to be concerned with the details of how a particular file format stores that metadata.

Another question is how can you use this data. You will receive just an array of bytes, and it is your problem how you interpret it. This library will simplify access to this image metadata by converting them to ordinary .NET data types and organizing them in the form of class properties and/or hashtable.

The primary source of information to write this class was MSDN.

MSDN Home > MSDN Library > Graphics and Multimedia > GDI+ > GDI+ Reference > Constants

I'd like also to thank Jeffrey S. Gangel whose article "Photo Properties" at CodeProject brought me to the idea to write this class. His program makes basically the same, the only difference is that I wanted to have image information in the form that seems to me to be more comfortable and conventional.

Not all image property tags are implemented as class properties. Those are accessible only from PropertyItems hashtable. If anyone needs this library at all and even needs the specific property, I'll be very glad to help him. But I think it is not necessary, because the whole source code is available and modifiable.

Usage

C#
// Accessing image proprties
public void ShowEquipModel() 
{ 
    Info inf=new Info("c:\\tmp\\Example.jpeg"); 
    MessageBox.Show(inf.EquipModel);
}
C#
// Accessing image proprties as a hastable 
public void ShowAllProperties() 
{ 
    Info inf=new Info("c:\\tmp\\Example.jpeg");
    listView.Items.Clear(); 
    foreach (string propertyname in inf.PropertyItems.Keys) {
        ListViewItem item1 = new ListViewItem(propertyname,0);
        item1.SubItems.Add((inf.PropertyItems[propertyname]).ToString());
        listView.Items.Add(item1); 
    } 
}

The properties of the Info class are listed below:

  • Brightness

    Brightness value. The unit is the APEX value. Ordinarily, it is given in the range of -99.99 to 99.99.

  • Copyright

    Copyright information.

  • DateTime

    Date and time the image was created.

  • DTDigitized

    Date and time when the image was stored as digital data. If, for example, an image was captured by DSC and at the same time the file was recorded, then DateTimeOriginal and DateTimeDigitized will have the same contents.

  • DTOrig

    Date and time when the original image data was generated. For a DSC, the date and time when the picture was taken.

  • EquipMake

    The manufacturer of the equipment used to record the image.

  • EquipModel

    The model name or model number of the equipment used to record the image.

  • ExposureProg

    Class of the program used by the camera to set exposure when the picture is taken.

  • FNumber

    F number.

  • FocalLength

    Actual focal length, in millimeters, of the lens. Conversion is not made to the focal length of a 35 millimeter film camera.

  • Image

    Sets or returns the current Image object.

  • ISOSpeed

    ISO speed and ISO latitude of the camera or input device as specified in ISO 12232.

  • MeteringMode

    Metering mode.

  • Orientation

    Image orientation viewed in terms of rows and columns.

  • PixXDim

    Type is PropertyTagTypeShort or PropertyTagTypeLong. Information specific to compressed data. When a compressed file is recorded, the valid width of the meaningful image must be recorded in this tag, whether or not there is padding data or a restart marker. This tag should not exist in an uncompressed file.

  • PixYDim

    Type is PropertyTagTypeShort or PropertyTagTypeLong. Information specific to compressed data. When a compressed file is recorded, the valid height of the meaningful image must be recorded in this tag whether or not there is padding data or a restart marker. This tag should not exist in an uncompressed file. Because data padding is unnecessary in the vertical direction, the number of lines recorded in this valid image height tag will be the same as that recorded in the SOF.

  • PropertyItems

    Returns a HashTable of all available properties of a given Image. Keys of this HashTable are display names of the Property Tags, and values are transformed (typed) data.

  • ResolutionUnit

    Unit of measure for the horizontal resolution and the vertical resolution. 2 - inch 3 - centimeter.

  • XResolution

    Number of pixels per unit in the image width (x) direction. The unit is specified by PropertyTagResolutionUnit.

  • YResolution

    Number of pixels per unit in the image height (y) direction. The unit is specified by PropertyTagResolutionUnit.

See also

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer
Germany Germany
Tweeter: @gmamaladze
Google+: gmamaladze
Blog: gmamaladze.wordpress.com

Comments and Discussions

 
QuestionSystem.OutOfMemoryException Pin
Marvin Vierling19-Apr-14 10:35
Marvin Vierling19-Apr-14 10:35 
QuestionThank a bunch Pin
Amit Andersen30-Nov-12 21:48
Amit Andersen30-Nov-12 21:48 
QuestionHow about Tags? Pin
Jenami671-Apr-12 3:58
Jenami671-Apr-12 3:58 
SuggestionMetadata Writing Feature Pin
Jenami671-Apr-12 3:52
Jenami671-Apr-12 3:52 
Generalsome questions Pin
Dirkus Maximus23-Nov-10 16:49
Dirkus Maximus23-Nov-10 16:49 
GeneralThanks! Pin
zamirinima10-Feb-10 4:50
zamirinima10-Feb-10 4:50 
QuestionCan I use this dll? Pin
jackhsu.1976tw30-Sep-08 1:10
jackhsu.1976tw30-Sep-08 1:10 
AnswerRe: Can I use this dll? Pin
George Mamaladze30-Sep-08 11:21
George Mamaladze30-Sep-08 11:21 
GeneralProblem - Image files are left locked Pin
johnieT23-Sep-08 3:50
johnieT23-Sep-08 3:50 
GeneralRe: Problem - Image files are left locked Pin
johnieT24-Sep-08 1:15
johnieT24-Sep-08 1:15 
QuestionTerms of Use? Pin
o m n i22-Apr-08 14:19
o m n i22-Apr-08 14:19 
AnswerRe: Terms of Use? Pin
George Mamaladze23-Apr-08 9:22
George Mamaladze23-Apr-08 9:22 
Questionsome EXIF data not being read on some files? Pin
todd.0101110116-Jan-08 14:50
todd.0101110116-Jan-08 14:50 
GeneralRe: some EXIF data not being read on some files? Pin
George Mamaladze16-Jan-08 22:56
George Mamaladze16-Jan-08 22:56 
GeneralRe: some EXIF data not being read on some files? Pin
todd.0101110117-Jan-08 8:58
todd.0101110117-Jan-08 8:58 
GeneralRe: some EXIF data not being read on some files? Pin
George Mamaladze17-Jan-08 10:06
George Mamaladze17-Jan-08 10:06 
GeneralRe: some EXIF data not being read on some files? Pin
todd.0101110119-Jan-08 15:57
todd.0101110119-Jan-08 15:57 
Hi George

Thanks for looking into it.

I found a post on an msdn blog that *might* provide a clue as to why Vista knows the original date taken, and it is not readable in the exif data.

I noticed that the EXIF 'Software' property said "Microsoft Windows Photo Gallery 6.0.6000.16386" That is the software used to download the pictures from the camera, and it may also be an ominous signature leading back to the cause of my problem.

That value indicates to me that the camera is not the only one writing to the EXIF data, and if photo gallery is writing to the EXIF data, maybe it has some hand in messing up the DTOrig value. Especially since, the vista file 'Details' tab is presumably reading from the XMP data, and IT contains the correct date taken.

The only place I figure photo gallery can get the DTOrig value in the first place is from the EXIF data, since the camera clearly wouldn't know how to write to both EXIF and XMP.

So.. following this theory, Windows Photo Gallery is using the DTOrig and copying it into the XMP formatted metadata and in doing so, somehow corrupting the DTOrig EXIF data - making it unreadable by yours or any other EXIF reader I've tried.

SO... all that being said, I'm going to try and experiment some more to explore my idea, and find a way to read that XMP meta data from the file.

Here's the blog post I referrerd to. If you have any insights, ideas, or advice, it's most certainly welcome.
http://blogs.msdn.com/pix/archive/2006/08/16/702780.aspx[^]

-Todd
GeneralRe: some EXIF data not being read on some files? Pin
todd.0101110119-Jan-08 18:21
todd.0101110119-Jan-08 18:21 
GeneralGreat work Pin
_dado_21-Apr-07 23:55
_dado_21-Apr-07 23:55 
GeneralRe: Great work Pin
bort_verdon25-Jul-10 9:32
bort_verdon25-Jul-10 9:32 
GeneralI used it, get the source Pin
motisaadon19-Mar-07 23:27
motisaadon19-Mar-07 23:27 
GeneralResolutionUnit Pin
damoose7521-Dec-06 2:26
damoose7521-Dec-06 2:26 
GeneralSpeed ups [modified] Pin
lummie25-Oct-06 7:53
lummie25-Oct-06 7:53 
GeneralExtract image (tiff and jpg) metadata Pin
mindang15-Oct-06 20:03
mindang15-Oct-06 20:03 
GeneralRe: Extract image (tiff and jpg) metadata Pin
George Mamaladze15-Oct-06 21:18
George Mamaladze15-Oct-06 21:18 

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

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