L_ReadFileCommentOffset

#include "l_bitmap.h"

L_LTFIL_API L_INT L_ReadFileCommentOffset(fd, nOffsetBegin, nBytesToLoad, uType, pComment, uLength, pLoadOptions)

Reads a comment from a file and lets you specify the location of the image data within the file. This enables you to read comments from an image file that is embedded in another file.

Parameters

L_HFILE fd

The Windows file handle of the file to load.

L_OFFSET nOffsetBegin

The position, from the beginning of the file, of the first byte to load.

L_OFFSET nBytesToLoad

The size of the embedded image file. (The embedded file may be a record within the larger file, and in such cases, this is the record size.)

L_UINT uType

The type of comment. Refer to Types of File Comments.

L_UCHAR* pComment

Pointer to your buffer that will hold the comment field, including the terminating NULL. You can pass NULL if you only want to get the length of the field (the return value).

L_UINT uLength

The size of your buffer that will hold the comment field.

pLOADFILEOPTION pLoadOptions

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

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

Like the L_ReadFileComment function, this function lets you read comments that are already saved in a file header. The only difference between the L_ReadFileComment function and this function is that this function allows you to specify an offset for the image data. For more information refer to the L_SetComment function.

The location of the image is specified as shown in the following simple illustration:

loadoff.bmp

You must open the file and get a Windows file handle before calling this function. Redirected input (specified with L_RedirectIO) is disabled when this function is executing.

Some file formats can contain comments, and some cannot, and each file format has its own set of comment types. When you save a file, the comments, which LEADTOOLS maintains in a global array, are saved in the file. The index into the array (specified using a constant) determines the type of comment, as described in Types of File Comments.

Before saving a file, you use the L_SetComment function to specify the comments to be saved.

Note: More options are available in the LOADFILEOPTION structure.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

The following sample will create a file with an offset and will read a comment from the file it just saved.

#define COMMENT "I am the artist!" 
 
L_INT ReadFileCommentOffsetExample(HWND hWnd) 
{ 
   BITMAPHANDLE Bitmap; 
   L_INT nRet; /* Return value */ 
   HANDLE OffsetFile = NULL; /* File handle */ 
   L_OFFSET zSizeWritten; /* Variable to be updated with the size written */ 
   DWORD dwSizeWrite; 
 
   /* Load an existing bitmap */ 
   nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("IMAGE1.FPX")),  
                       &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet != SUCCESS) 
   { 
      MessageBox(hWnd, TEXT("Load has failed!"), TEXT("FAILURE"), MB_OK); 
      return nRet; 
   } 
 
   OffsetFile = CreateFile(MAKE_IMAGE_PATH(TEXT("TOFFSET.TST")), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); 
 
   /* Write some text in the file -- 29 characters and a terminator */ 
   WriteFile(OffsetFile, "This is a 29-character string", 30, &dwSizeWrite, NULL); 
 
   /* set and save a comment into a file with an offset */ 
   nRet = L_SetComment(CMNT_SZARTIST, (L_UCHAR *)COMMENT, sizeof(COMMENT)); 
 
   /* Save the image file with an offset inside the TOFFSET.TST file */ 
   nRet = L_SaveFileOffset((L_HFILE) OffsetFile, 30, &zSizeWritten, &Bitmap, FILE_TIF, 1, 0, SAVEFILE_FIXEDPALETTE, NULL, NULL, NULL); 
 
   /* Close the file */ 
   CloseHandle(OffsetFile); 
 
   /* free the bitmap */ 
   if(Bitmap.Flags.Allocated)    
      L_FreeBitmap(&Bitmap); 
 
   /* Notify the user with a message box */ 
   if (nRet != SUCCESS) 
   { 
      MessageBox (NULL, TEXT("Error saving file"), TEXT("Error"), MB_OK); 
      return nRet; 
   } 
 
   /* Now load the file we just saved       */ 
   /* Open the file and get the file handle */ 
   OffsetFile = CreateFile(MAKE_IMAGE_PATH(TEXT("TOFFSET.TST")), GENERIC_READ , 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 
 
   /* Get the comment size */ 
   nRet = L_ReadFileCommentOffset((L_HFILE) OffsetFile, 30, zSizeWritten, 
                                  CMNT_SZARTIST, NULL, 0, NULL); 
   if(nRet > 0) 
   { 
      /* Allocate a buffer for the comment. Allocate extra byte for string terminator */ 
      L_CHAR *pComment = (L_CHAR *)malloc((nRet + 1) * sizeof(L_CHAR)); 
      nRet = L_ReadFileCommentOffset((L_HFILE) OffsetFile, 30, zSizeWritten, 
               CMNT_SZARTIST,(L_UCHAR *)pComment, nRet + 1, NULL); 
      if(nRet > 0) 
      { 
         /* make sure the string is NULL-terminated */ 
         MessageBoxA(hWnd, pComment, ("SUCCESS"), MB_OK); 
      } 
      free(pComment); 
   } 
 
   /* Close the file */ 
   CloseHandle(OffsetFile); 
   return SUCCESS; 
} 

Help Version 20.0.2020.4.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help