L_ReadFileTags

#include "l_bitmap.h"

L_LTFIL_API L_INT L_ReadFileTags(pszFile, uFlags, puTagCount, ppTags, puDataSize, ppData, pLoadOptions)

L_TCHAR * pszFile;

/* input file name */

L_UINT uFlags;

/* control flags */

L_UINT* puTagCount;

/* number of tags found */

pLEADFILETAG* ppTags;

/* address of the variable for tag data */

L_SIZE_T* puDataSize;

/* the overall size of the tags data */

L_UCHAR** ppData;

/* the overall tags data */

pLOADFILEOPTION pLoadOptions;

/* pointer to optional extended load options */

Gets all the tags stored in a file.

Parameter

Description

pszFile

Character string that contains the input file name.

uFlags

Flag that determines whether to read the tag overall data. You can combine values when appropriate by using a bitwise OR ( | ):

 

Flag

Meaning

 

READFILEMETADATA_NOMEMORY

[0x01] Do not read the tag overall data. If this flag is set, then puDataSize and ppData will not be used and the function will not read the tag overall data.

puTagCount

Address of the variable to be updated with the number of tags found in the file.

ppTags

Pointer to an array of pLEADEADFILETAG structures. Each element of the array contains data for one tag found in the file. The number of elements in ppTags is puTagCount. When this array is no longer needed pass it to the L_FreeFileTags function to free the allocated memory.

puDataSize

Address of the variable to be updated with the size in bytes of the overall tags data.

ppData

Address of the variable to be updated with a pointer to the overall tags data. The size of this pointer in bytes is puDataSize. Each LEADEADFILETAG item found contains an offset to where the data for this item is stored in ppData.

pLoadOptions

Pointer to optional extended load options. Pass NULL to use the default load options

Returns

SUCCESS

The function was successful

< 1

An error occurred. Refer to Return Codes.

Comments

You must free the data allocated with this function using the L_FreeFileTags function.

For general information about TIFF tags, refer to Implementing TIFF Comments and Tags.

Required DLLs and Libraries

LTFIL

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 2000 / XP/Vista, Windows CE.

See Also

Functions:

L_SetTag, L_GetTag, L_ReadFileTag, L_FreeFileTags

Topics:

Implementing TIFF Comments and Tags

Example

This example will read all the tags, comments and geo keys stored in a disk file.

 L_INT ReadFileTagsExample(L_VOID)
{
   FILEINFO fi;
   L_INT nRet;
   L_UINT i, uTagCount, uCommentCount, uGeoKeyCount;
   pLEADFILETAG pTags = NULL, pCurrentTag, pGeoKeys = NULL, pCurrentGeoKey;
   L_SIZE_T uTagDataSize = 0, uCommentDataSize = 0, uGeoKeyDataSize = 0;
   L_UCHAR *pTagData = NULL, *pCommentData = NULL, *pGeoKeyData = NULL;
   L_CHAR *pszAscii = NULL;
   pLEADFILECOMMENT pComments = NULL, pCurrentComment;
   L_TCHAR szImageFileName[] = TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\image1.jpg");

   // Get the format of the file
   ZeroMemory(&fi, sizeof(FILEINFO));
   fi.uStructSize = sizeof(FILEINFO);
   nRet = L_FileInfo(szImageFileName, &fi, sizeof(FILEINFO), 0, NULL);
   if(nRet != SUCCESS)
      return nRet;

   // Read all the tags in the file
   if(nRet == SUCCESS && L_TagsSupported(fi.Format))
   {
      // Yes, read all the tags from the file
      nRet = L_ReadFileTags(
         szImageFileName,
         0,
         &uTagCount,
         &pTags,
         &uTagDataSize,
         &pTagData,
         NULL);
   }

   // Read all the comments in the file
   if(nRet == SUCCESS && L_CommentsSupported(fi.Format))
   {
      // Yes, read all the comments from the file
      nRet = L_ReadFileComments(
         szImageFileName,
         0,
         &uCommentCount,
         &pComments,
         &uCommentDataSize,
         &pCommentData,
         NULL);
   }

   // Read all the geo keys in the file
   if(nRet == SUCCESS && L_GeoKeysSupported(fi.Format))
   {
      // Yes, read all the geo keys from the file
      nRet = L_ReadFileGeoKeys(
         szImageFileName,
         0,
         &uGeoKeyCount,
         &pGeoKeys,
         &uGeoKeyDataSize,
         &pGeoKeyData,
         NULL);
   }

   if(nRet == SUCCESS)
   {
      if(uTagCount > 0)
      {
         // Show the tags
         wprintf(L"Tags\n");
         for(i = 0; i < uTagCount; i++)
         {
            pCurrentTag = &pTags[i];

            // If this tag is of type ASCII, get its data
            if(pCurrentTag->uType == TAG_ASCII)
            {
               pszAscii = (L_CHAR*)malloc(pCurrentTag->uDataSize + 1);
               ZeroMemory(pszAscii, pCurrentTag->uDataSize + 1);
               CopyMemory(pszAscii, pTagData + pCurrentTag->uDataOffset, pCurrentTag->uDataSize);
            }
            else
            {
               pszAscii = NULL;
            }

            printf("Id: 0x%X, data length: %u, data: %s\n", pCurrentTag->uTag, pCurrentTag->uDataSize, pszAscii != NULL ? pszAscii : "Binary data");
         }

         L_FreeFileTags(uTagCount, pTags, uTagDataSize, pTagData);
      }

      if(uCommentCount > 0)
      {
         // Show the Comments
         wprintf(L"Comments\n");
         for(i = 0; i < uCommentCount; i++)
         {
            pCurrentComment = &pComments[i];

            // If this comment is of type ASCII, get its data
            printf("Id: 0x%X, data length: %u\n", pCurrentComment->uType, pCurrentComment->uDataSize);
         }

         L_FreeFileComments(uCommentCount, pComments, uCommentDataSize, pCommentData);
      }

      if(uGeoKeyCount > 0)
      {
         // Show the geo keys
         wprintf(L"GeoKeys\n");
         for(i = 0; i < uGeoKeyCount; i++)
         {
            pCurrentGeoKey = &pGeoKeys[i];

            // If this geo key is of type ASCII, get its data
            if(pCurrentGeoKey->uType == TAG_ASCII)
            {
               pszAscii = (L_CHAR*)malloc(pCurrentGeoKey->uDataSize + 1);
               ZeroMemory(pszAscii, pCurrentGeoKey->uDataSize + 1);
               CopyMemory(pszAscii, pGeoKeyData + pCurrentGeoKey->uDataOffset, pCurrentGeoKey->uDataSize);
            }
            else
            {
               pszAscii = NULL;
            }

            printf("Id: 0x%X, data length: %u, data: %s\n", pCurrentGeoKey->uTag, pCurrentGeoKey->uDataSize, pszAscii != NULL ? pszAscii : "Binary data");
         }

         L_FreeFileTags(uGeoKeyCount, pGeoKeys, uGeoKeyDataSize, pGeoKeyData);
      }
   }
   return SUCCESS;
}