Help with MetaData in VB6

Developers
2012-07-10
2012-10-31
  • Brian Salapek
    Brian Salapek
    2012-07-10

    Hello Everyone,
    I apologize if this has been covered but I am having issues with meta data in
    my VB6 project. Everything seems fine when writing the Meta Data. Here is the
    code:

    Dim hBitmap As Long, bsTag As FREE_IMAGE_TAG

    hBitmap = FreeImage_LoadEx(App.Path & "\Test123.JPG", JPEG_ACCURATE)
    bsTag = FreeImage_CreateTagEx(FIMD_COMMENTS, "TestMeta", FIDT_ASCII,
    Text1.Text, 1, 0)

    FreeImage_SetMetadataEx hBitmap, bsTag, "TestMeta", FIMD_COMMENTS, True

    Call FreeImage_UnloadEx(hBitmap)

    But when I try to retrieve the Meta Data, it does not work. The PDF Help file
    only contains C++(?) code which does not translate to VB6 as expected data
    types differ. Here is the code I am working with:

    Dim hBitmap As Long, bsTag As FREE_IMAGE_TAG

    hBitmap = FreeImage_LoadEx(App.Path & "\Test123.JPG", JPEG_ACCURATE)
    FreeImage_GetMetadataEx FIMD_COMMENTS, hBitmap, "TestMeta", bsTag

    Call FreeImage_UnloadEx(hBitmap)

    Any help would be appreciated. Thank you.

     
  • Brian Salapek
    Brian Salapek
    2012-07-10

    Update (even though it seems to be going on to deaf ears)
    I have realized there is a problem with my code above. When I write the Meta
    Data, I forgot the code to resave the image. I added the line:
    bOK = FreeImage_Save(FIF_JPEG, hBitmap, App.Path & "\Test123.JPG",
    JPEG_QUALITYSUPERB)

    While it does not work, still, there is something interesting happening. If I
    were to change the name of the "Key" to "Comment" instead of "TestMeta", it
    saves and is able to be reloaded. It is as if "Comment" is already built into
    the file while any others need to told to be saved perhaps?

     
  • Carsten Klein
    Carsten Klein
    2012-07-10

    Hi Brian,

    yes, the PDF contains the C/C++ declarations of the FreeImage API functions.
    However, it also tells you a lot about metadata and FreeImage's metadata
    models. Each model (FIMD_COMMENTS, EXIF_MAIN, etc.) has its own set of valid
    and recognized keys. Only those keys are actually written to an image file
    (and also read from it).

    The Freeimage metadata models are just a convenience API, that provide
    different metadata with a unique interface. However, the tag's keys (aka
    names) are the key to make the translation to an image format's internal
    representation of the data work. For instance, metadata model FIMD_COMMENTS
    only uses one key which must be named "Comment" to provide access to an
    image's comment. Other models, like FIMD_XMP, which is XML-based, uses a
    single tag named "XMLPacket". Other models use a set of several keys.

    You will find that and a lot more about metadata in the FreeImage API
    Documentation (the PDF document).
    Get it, read it, enjoy...

    There are wrapper functions available in the VB6 wrapper for accessing an
    image's comment. Have a look a methods FreeImage_Get/SetImageComment.

    BTW, try function FreeImage_GetAllMetadataTags, which is a VB6 wrapper
    function to read all of an metadata model's tags. Applied to an image from
    your photo camera, it will give you a short overview of the various metadata
    models and tag keys FreeImage supports.

    Carsten

     
  • Brian Salapek
    Brian Salapek
    2012-07-11

    Carsten,
    I really appreciate your help on this issue. I had not realized that the
    models each had finite keys. I have used the example you provided, FIMD_XMP
    and XMLPacket to store the data I wish to store. Thank you very much for your
    help.