Menu

Enumerate EXIF in VB6 - Is it possible?

Don Juane
2011-10-12
2012-10-31
  • Don Juane

    Don Juane - 2011-10-12

    I have been searching for a long time for a dependable way to extract EXIF
    from a JPG using Visual Basic 6. I have tired all the online VB6 API offerings
    (i.e. ExifReader.cls, clsImageInfo.cls, clsJPEGparser.cls) and each one of
    them always encounters occasionally a JPG it can't process (API code abends,
    while other applications such as IrfanView have no problem displaying the EXIF
    data for the JPG). My problem is I don't know win32 API well enough nor the
    EXIF model so I can't debug the VB6 CLS examples that occasionally fail.

    This issue caused me to try FreeImage from VB6, however after a couple of days
    I finally give up searching online for any examples calling FreeImage from VB6
    for metadata. Today I thought I would make one last attempt and scanned the
    VB.Net examples. I found a ~30 line example (Sample 10) from the package that
    was promising but confusing since I have never coded in .NET. I did manage to
    figure out that Sample 10 from the group depends literally on thousands of
    lines of class library code in order to iterate the EXIF data via FreeImage. I
    found this from .NET class libraries ImageMetadata.cs, MetadaaModel.cs and
    MetadataTag.cs.

    So it seems that extracting EXIF is an even greater task than I expected. With
    no examples to get at Metadata by calling FreeImage from VB6 it sounds like
    the only solution may be to go back to one of the VB6 CLS files and try to
    debug the API with documentation on EXIF for the rare oddity where the API
    fails.

    Am I wrong or am I wrong? (Thanks!)

     
  • Don Juane

    Don Juane - 2011-10-12

    Finally! I struck upon something popular that makes sense, the PHP example. I
    was able to learn enough from the PHP code to make something that works in
    VB6. Here is a starter for anyone else who can't seem to get off the ground
    with the 1 line VB6 example ;-) :

    Note: Add or replace this code in the FileImage package:

    FreeImage3151Win32\FreeImage\Wrapper\VB6\test

    Replace existing code in SimpleTest.frm with this to test metadata:

    Option Explicit
    ' NOTE :
    ' To run this test program, you will have to copy the FreeImage.dll file in this directory.
    ' Change also the "test.tif" file name with a path to any tif file on your hard disk
    '
    Private Sub btnTest_Click()
      Dim tstText As String
      Dim dib As Long
      Dim bOK As Long
      Dim i As Long
      Dim tstTag() As FREE_IMAGE_TAG
    
      dib = FreeImage_Load(FIF_JPEG, "IMG_5061.JPG", 0) 'in our source dir for testing
    
      tstText = "FIMD_EXIF_EXIF"
      Erase tstTag
      bOK = FreeImage_GetAllMetadataTags(FIMD_EXIF_EXIF, dib, tstTag())
      If bOK > 0 Then
        For i = 1 To UBound(tstTag) - 1
            tstText = tstText & vbCrLf & tstTag(i).Description & ":    " & tstTag(i).Key & " = " & tstTag(i).StringValue
        Next
        MsgBox tstText
      Else
        MsgBox "Nothing returned for FIMD_EXIF_EXIF"
      End If
    
       tstText = "FIMD_EXIF_MAIN"
       Erase tstTag
      bOK = FreeImage_GetAllMetadataTags(FIMD_EXIF_MAIN, dib, tstTag())
      If bOK > 0 Then
        For i = 1 To UBound(tstTag) - 1
            tstText = tstText & vbCrLf & tstTag(i).Description & ":    " & tstTag(i).Key & " = " & tstTag(i).StringValue
        Next
        MsgBox tstText
      Else
        MsgBox "Nothing returned for FIMD_EXIF_MAIN"
      End If
    
      tstText = "FIMD_EXIF_INTEROP"
      Erase tstTag
      bOK = FreeImage_GetAllMetadataTags(FIMD_EXIF_INTEROP, dib, tstTag())
      If bOK > 0 Then
        For i = 1 To UBound(tstTag) - 1
            tstText = tstText & vbCrLf & tstTag(i).Description & ":    " & tstTag(i).Key & " = " & tstTag(i).StringValue
        Next
        MsgBox tstText
      Else
        MsgBox "Nothing returned for FIMD_EXIF_INTEROP"
      End If
    
      ' Unload the dib
    

    FreeImage_Unload (dib)

    End Sub

    At least this will get me started. Good luck to everyone else searching for a
    similar solution and please share your own discoveries .... Don

     
  • Don Juane

    Don Juane - 2011-10-13

    Notice above, the last two lines jumped out of my shaded code block:

    .......... (see above)
    
    ' Unload the dib
      FreeImage_Unload (dib)
    
    End Sub
    
     
  • Don Juane

    Don Juane - 2011-10-13

    And the hits just keep on comin'!

    Here is a way to find the DateTimeOriginal value of a JPG with a little
    "minimalism" of my own :-)

    Private Sub CreateDate(myJPG as string)
      Dim keySearch As String
      Dim dib As Long
      Dim bDone As Boolean
      Dim tstTag As FREE_IMAGE_TAG
    
      dib = FreeImage_Load(FIF_JPEG, myJPG, 0) 'in our source dir for testing
    
      keySearch = "DateTimeOriginal"
    
      bDone = FreeImage_GetMetadataEx(FIMD_EXIF_EXIF, dib, keySearch, tstTag)
      If bDone Then
            MsgBox tstTag.Key & " = " & tstTag.StringValue
      Else
        MsgBox "Not found"
      End If
    
      ' Unload the dib
      FreeImage_Unload (dib)
    End Sub
    
     
  • Carsten Klein

    Carsten Klein - 2011-10-13

    Hi,

    I gave you a complete example including a lot more information about metadata
    extraction with FreeImage from VB6 yesterday. Maybe you should monitor the
    forums you are posting to...

    https://sourceforge.net/projects/freeimage/forums/forum/36110/topic/4752688

    Carsten

     
  • Don Juane

    Don Juane - 2011-10-13

    "Maybe you should monitor the forums you are posting to..."

    Hello Carsten:

    I checked the "Monitor" button but I got no emails stating anything was
    updated. I am not sure how this one works but I certainly didn't mean to
    offend you or anyone else. I do admit that I just registered for this forum
    and have never used SourceForge fora prior to these last couple of posts. My
    only experience is that in other fora I can subscribe to threads and here I
    assumed that " |_| Monitor This " check box meant that I would be put on a
    mailing list when it was updated. If that is not the way it works, my advanced
    apologies. You are correct that I depend on notification automation for
    updates and if I don't get an email, then I assume no one updated and don't go
    back and check it often otherwise.

    Apparently this forum does not update either, as I found your post by accident
    just now as I was about to add more information that I have gathered.

     
  • Don Juane

    Don Juane - 2011-10-13

    Casten gave a great example in his referenced link above so please refer to
    that for the correct way to go about this. Thank you so much. See his link for
    further information. As a final post, I do want to close this out with some
    further info on the code above, junky as it is. Note that the EXIF data
    overfills a msgbox call so you won't see all the EXIF data it extracts, so I
    have entered a typical test run output below.

    For reference, here is the data I got from the respective calls from a Canon
    SD850:

    FIMD_EXIF_EXIF:
    ApertureValue = F2.8
    ColorSpace = sRGB
    ComponentsConfiguration = YCbCr
    CompressedBitsPerPixel = 5 bits/pixel
    CustomRendered = Normal process
    DateTimeDigitized = 2010:07:01 15:20:00
    DateTimeOriginal = 2010:07:01 15:20:00
    DigitalZoomRatio = 3264/3264
    ExifVersion = 0220
    ExposureBiasValue = 0
    ExposureMode = Auto exposure
    ExposureTime = 1/60 sec
    FNumber = F2.8
    FileSrc = Digital Still Camera (DSC)
    Flash = Flash did not fire, auto mode
    FlashPixVersion = 0100
    FocalLength = 5.8 mm
    FocalPlaneResolutionUnit = inches
    FocalPlaneXResolution = 43520/3
    FocalPlaneYResolution = 2448000/169
    ISOSpeedRatings = 125
    MaxApertureValue = F2.8
    MeteringMode = Multi-segment
    PixelXDimension = 900
    PixelYDimension = 675
    SceneCaptureType = Standard
    SensingMethod = One-chip color area sensor
    ShutterSpeedValue = 1/32 sec
    SubjectDistance = 0.560 meters
    UserComment =

    FIMD_EXIF_INTEROP:
    InteroperabilityIndex = R98
    InteroperabilityVersion = 0100
    RelatedImageLength = 2448

    FIMD_EXIF_MAIN:
    BitsPerSample = 8 8 8
    DateTime = 2011:10:10 21:09:46
    ImageLength = 2448
    ImageWidth = 3264
    Make = Canon
    Model = Canon PowerShot SD850 IS
    Orientation = top, left side
    PhotometricInterpretation = 2
    ResolutionUnit = inches
    SamplesPerPixel = 3
    Software = Adobe Photoshop CS5 Windows
    XResolution = 180
    YCbCrPositioning = Center of pixel array

     

Log in to post a comment.

Auth0 Logo