Mark Michaelis' Weblog :
Updated: 9/1/2004; 6:54:45 AM.

 








Subscribe to "Mark Michaelis' Weblog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

Subscribe To
Mark's Weblog

 
 

Monday, December 30, 2002

Retrieving Meta Data from JPEG Files Using C#
Google Search It

To night I worked on figuring out a storage location for comments and the like relating to images.  Since windows provides a file properties dialog with a summary tab that allows one to enter such meta data as author, comments, subject, title etc. this seems like a logical location to store the data.  I went ahead and modified the data using the Windows Explorer and then proceeded to figure out where the data was stored.  It appears that it is located in some of EXIF properties on the JPEG file.  To find out the exact location I wrote the following C# program:

using System;
// A manual reference to System.Drawing.DLL needs to be made.
using System.Drawing;
using System.Drawing.Imaging;
namespace FunWithImages
{
  class EntryPoint
  {
    [STAThread]
    static void Main(string[] args)
    {
      Image image = new Bitmap(@"..\..\tower.jpg");
      PropertyItem item;
      foreach( int id in image.PropertyIdList )
      {
        try 
        {
          item = image.GetPropertyItem( id );
          System.Console.Write(
            string.Format("{0:20} - {1:20}(0x{2:x})",
            ((ImagePropertyIDTags)item.Id).ToString(),
            ((ImagePropertyTtypes)item.Type).ToString(),
            item.Id)
            );
          for(int i = 0; i < (item.Len -1); i++)
          {
            if(((char)item.Value[i])!='n')
              System.Console.Write((char)item.Value[i]);
          
          System.Console.WriteLine();
                                                            
        }
        catch( Exception exception) 
        {
          Console.WriteLine("ERROR: {0}", exception);
        }
      }
    }
  }
}

The output from the program displays the image tag, type, id and value information.  In order for this to work I had to create enums for the standard image type tags and image property tags.  You can retrieve these definitions from here (I use the TXT extension so download is easy).  This file was created from GDIConstants.h.

What is interesting is that the tags used by the Windows File Explorer Summary tab are not standard.  Instead the ids for these items range from 40091 on up (to 40095 in my one experiment).  To verify that these were not standard I downloaded JPEG Comment Editor 1.0 to see which tag it modified.  It turned out to be the PropertyTagExifUserComment tag (not the same as the 40092 tag used by the summary tab.)  Interesting....

Anyway, the bottom line is that the EXIF properties seem like a viable location for storing the data.  The advantage over XML or some such is that they are bound and automatically associated with the picture.  This seems significant to me. 

Next on the agenda is to determine how to write to the properties from code and then to retrieve the metadata for a web page.  I have a strong inclination at the moment to update the SourceForge PhotoRoom Project to display this metadata.  One detail to check, however, is how much data can be placed in one of the properties?


3:45:28 AM   []    comment []

Here's another Windows XP tip I never new.  You can rename multiple files simultaneously.  Windows XP will automatically append a parenthesis and number for you.  This will be great for pictures I expect.
12:19:40 AM   []    comment []

© Copyright 2004 Mark Michaelis.



 


December 2002
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Nov   Jan


Recent Posts