Saturday, January 8, 2011

GETTING METADATA INFORMATION FROM YOUR PICTURES WITH GDI+


Did you know that all the JPEGs from your digital camera contain a lot of extra information ?
We can easily retrieve some interesting information such as : Title, Equipment Make, Camera Model, Shutter Speed, Lens Aperture, Flash Mode, Date of Picture, and much more ! These metadata "tags" are stored in a JPEG file to indicate various camera settings and picture taking conditions that occurred while creating the photo. Several image file formats enable you to store metadata along with an image, such as JPEG, TIFF and PNG.

Again GDI+ makes our lives easier, providing to us a function to get these information : GetPropertyItem, stored in the GpImage class from _gdiplus.vcx .
Download and execute this file, and select an image from any Digital Camera, and you'll see all metadata stored in it.
On the first part of this code, I get the most common properties, from the GpImage class, like ImageWidth, ImageHeight, HorizontalResolution, VerticalResolution and PixelFormat.
On the rest I retrieve the metadata from the image file, using GetPropertyIdList and GetPropertyItem. It's important to notice that GetPropertyIdList receives an array as a parameter, and returns that array populated with the metadata.
lcSource = GETPICT()
LOCAL loImage AS GpImage OF ffc/_gdiplus.vcx
loImage = NEWOBJECT("GpImage", HOME() + "ffc/_gdiplus.vcx")
loImage.CreateFromFile(lcSource)

DIMENSION raPropIDList(1)
LOCAL nCount, n, lcTagName, lnProp, luProp

nCount = loImage.GetPropertyIdList(@raPropIDList)
FOR n = 1 TO nCount
   lnProp = raPropIDList(n)
   luProp = loImage.GetPropertyItem(lnProp)

   ? TRANSFORM(lnProp), TRANSFORM(luProp)
ENDFOR

It is possible to get some other really cool information from pictures.
Take a look at the 2 last items in the picture, ExifLightSource and ExifFlash. In both cases we have a zero value. Check this table, to see what each possible value could mean :
TagID : 0x9208 (37384) - LightSource int16u ExifIFD        
     1 = Daylight                                          
     2 = Fluorescent                                       
     3 = Tungsten                                          
     4 = Flash                                             
     9 = Fine Weather                                      
    10 = Cloudy                                            
    11 = Shade                                             
    12 = Daylight Fluorescent                              
    13 = Day White Fluorescent                             
    14 = Cool White Fluorescent                            
    15 = White Fluorescent                                 
    17 = Standard Light A                                  
    18 = Standard Light B                                  
    19 = Standard Light C                                  
    20 = D55                                               
    21 = D65                                               
    22 = D75                                               
    23 = D50                                               
    24 = ISO Studio Tungsten                               
   255 = Other                                               

TagID : 0x9209 (37385) - Flash int16u ExifIFD              
   0x0 = No Flash                                          
   0x1 = Fired                                             
   0x5 = Fired, Return not detected                        
   0x7 = Fired, Return detected                           
   0x9 = On                                                
   0xd = On, Return not detected                           
   0xf = On, Return detected                               
  0x10 = Off                                               
  0x18 = Auto, Did not fire                                
  0x19 = Auto, Fired                                       
  0x1d = Auto, Fired, Return not detected                  
  0x1f = Auto, Fired, Return detected                      
  0x20 = No flash function                                 
  0x41 = Fired, Red-eye reduction                          
  0x45 = Fired, Red-eye reduction, Return not detected    
  0x47 = Fired, Red-eye reduction, Return detected         
  0x49 = On, Red-eye reduction                             
  0x4d = On, Red-eye reduction, Return not detected        
  0x4f = On, Red-eye reduction, Return detected            
  0x59 = Auto, Fired, Red-eye reduction                    
  0x5d = Auto, Fired, Red-eye reduction, Return not detected
  0x5f = Auto, Fired, Red-eye reduction, Return detected     
At this link you can find some other great information about Metadata tags :
http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html
It is obviously possible to remove, change or set the metadata property items from images with GDI+ too, but for this task, it is necessary use some extra code, once _gdiplus.vcx doesn't bring this feature.
You can download the sample file from here http://weblogs.foxite.com/cesarchalom/attachment/1252.ashx

No comments:

Post a Comment