Foxite.COM Community Weblog

Foxite.COM Community Weblog - free weblog service for the Visual FoxPro Community.
Welcome to Foxite.COM Community Weblog Sign in | Join | Help
in
Home Blogs Forum Photos Forum Archives

VFP IMAGING



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

 

Comment added in 04/06/06

I wrote a much more detailed article on this subject to the UniversalThread Magazine published in the April/2006 issue.

It's really worth to have a look there, where you will find a subclass for GpImage that permits to you to Read, Write or Remove Image Tags.

You can create a simple procedure to add information to the pictures that you distribute or generate with your projects, etc.

To see the article, all you need is to pass your login and password. If you still don't have one, hurry to do it, because Michel Fournier has just opened all the contents of all issues of the magazine to all the community. Sign up for free NOW !!!

http://www.utmag.com/wconnect/wc.dll?9,7,10,,2090

 

Published Thursday, March 02, 2006 3:31 AM by cesarchalom
Filed Under:
Attachment(s): getmetadata.zip

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Ana María Bisbé said:

Versión en Español de este artículo en / Spanish version at http://www.portalfox.com/index.php?name=News&file=article&sid=2188
July 24, 2007 6:37 PM

What do you think?

(required) 
(optional)
(required)