Products | Support | Send comments on this topic. | Email a link to this topic. | Back to Getting Started | Help Version 18.0.10.24
LEADTOOLS Raster imaging C++ Class library help

LFile::ReadComment

Show in webframe

#include "ltwrappr.h"

virtual L_INT LFile::ReadComment(uType, pLBuffer, pLoadFileOption=NULL)

L_UINT uType;

/* type of comment*/

LBuffer * pLBuffer;

/* pointer to a buffer object */

pLOADFILEOPTION pLoadFileOption;

/* pointer to optional extended load options */

Gets a single comment, a group of comments or several groups of comments from a file.

Parameter

Description

uType

The type of comment. Refer to Types of File Comments. A group of comments may be obtained such as CMNT_FPXSUMMARYINFORMATION, or more than one group of comments may be retrieved by using OR as in CMNT_FPXSUMMARYINFORMATION | CMNT_FPXFILESOURCEGROUP, or all comments may be obtained by using CMNT_ALL. See Example listed below. For more information concerning FlashPix file comments, see FlashPix File Comments.

pLBuffer

Pointer to the buffer object that will hold all the comments.

pLoadFileOption

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

Returns

>=0

Length of the comment field.

< 0

An error occurred. Refer to Return Codes.

Comments

The basic order of function calls to retrieve comments is as follows:

Get the size of the comments with LFile::GetCommentSize

Allocate a buffer of a corresponding size.

Read the comments with LFile::ReadComment

Free the buffer

To write comments to a file, all the comments you wish to add to a new file must be set. LFileSettings::SetComment sets each comment individually, but it does not save the comments to the file, it prepares the values for the next save.. Once all comments are set, the comments are saved using any function which saves files, such as LFile::SaveFile or LFile::Save when creating a new file. If you wish to change a comment in an existing file, use LFile::WriteComment.

Required DLLs and Libraries

LTFIL
File format DLLs

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

Win32, x64.

See Also

Functions:

LFile::ReadCommentOffset, Class Members

Topics:

Raster Image Functions: Maintaining File Comments

 

Loading and Saving Images

Example

This example demonstrates all of the functions related to comments for TIFF files.

It clears all comments, sets a new comment, gets the comment from memory,

saves a file with the comment, then gets the comment from the file.

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
L_INT LFile__ReadCommentExample() 
{
   L_INT nRet;
   L_INT CommentLength; 
   LBitmap LeadBitmap;
   LFileSettings fileSettings;
   HGLOBAL hTextToGet;
   L_CHAR *pTextToSet = "Susie, the artist";
   L_CHAR *pTextToGet;
   L_TCHAR message[200]; 
   //Set the comment
   nRet = fileSettings.SetComment(CMNT_SZARTIST, (L_UCHAR *)pTextToSet, (L_INT) (strlen(pTextToSet) + 1));
   if(nRet < 0)
      return nRet;
   //Get the length of a comment
   CommentLength = fileSettings.GetComment(CMNT_SZARTIST, NULL, 0);
   //Allocate and lock a zero-filled buffer for the comment
   hTextToGet = GlobalAlloc(GPTR, CommentLength);
   pTextToGet = (L_CHAR *)GlobalLock(hTextToGet);
   //Get the actual comment
   fileSettings.GetComment(CMNT_SZARTIST, (L_UCHAR *)pTextToGet, CommentLength);
   //Show the comment that will be saved
   wsprintf(message,TEXT(" %hs"),pTextToGet);
   ::MessageBox(NULL, message, TEXT("Saving Artist Comment"), MB_OK);
   // Free memory
   GlobalUnlock(hTextToGet);
   GlobalFree(hTextToGet);
   //Load, and then save the image with the new comment
   LeadBitmap.SetFileName(MAKE_IMAGE_PATH(TEXT("clean.tif")));
   nRet = LeadBitmap.Load();
   if(nRet != SUCCESS)
      return nRet;
   LeadBitmap.SetFileName(MAKE_IMAGE_PATH(TEXT("output.tif")));
   nRet = LeadBitmap.Save(FILE_TIF, 8, 0, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;
   //Get the length of a comment in the file 
   CommentLength = LeadBitmap.File()->ReadComment(CMNT_SZARTIST, NULL);
   //Get the actual comment from the file
   LBuffer LeadBuffer(CommentLength);
   nRet = LeadBitmap.File()->ReadComment(CMNT_SZARTIST, &LeadBuffer);
   if(nRet < 1)
      return nRet;
   //Show the comment that was saved in the file 
   wsprintf(message,TEXT(" %hs"),LeadBuffer.Lock());
   ::MessageBox (NULL, message, TEXT("Artist comment"), MB_OK);
   LeadBuffer.Unlock();
   return SUCCESS;
}
Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.