Comment example for C++ Builder
This example does the following:
1. |
Loads an image from a TIFF file. |
2. |
Updates the current comment array by reading comments from the file. |
3. |
Modifies one of the comments. |
4. |
Modifies and saves the file. |
5. |
Reads the comment that was saved, and displays it in a message box. |
|
This example handles only string comments. For more complex comments, refer to Exif Examples. |
void __fastcall TForm1::ReadComment1Click(TObject *Sender)
{
Variant Empty; /* For clearing comments */
AnsiString MyCommentText; /* String for CMNT_SZDESC */
AnsiString NewCommentText; /* String for CMNT_SZDESC that we read */
AnsiString FilePath; /* File to be updated */
int i; /* Counter */
/* Specify the file that we will update. */
FilePath = "c:\\ testcmt.tif";
/* Specify the Empty variant for clearing comments. */
VarClear(Empty);
/* Get all of the current comments from the file. */
/* Temporarily disable method errors so that we do not fail when comments are missing. */
LeadImage1->EnableMethodErrors = False;
for (i = 0; i <= CMNT_LAST; i++)
{
LeadImage1->Comment[i] = Empty;
LeadImage1->Comment[i] = LeadImage1->ReadComment(FilePath, 0, i);
}
LeadImage1->EnableMethodErrors = True;
/* Load and modify the image. */
LeadImage1->Load(FilePath, 0, 0, 1);
LeadImage1->Reverse();
/* Update the CMNT_SZDESC comment. */
MyCommentText = "\nThis image has been reversed.";
LeadImage1->Comment[CMNT_SZDESC] = LeadImage1->Comment[CMNT_SZDESC] + MyCommentText;
/* Save the file and read the comment that we saved. */
LeadImage1->Save(FilePath, FILE_TIF, LeadImage1->BitmapBits, 0, SAVE_OVERWRITE);
NewCommentText = LeadImage1->ReadComment(FilePath, 0, CMNT_SZDESC);
/* Display the message. */
Application->MessageBox(NewCommentText.c_str(), "File Comments", MB_OK);
/* Clear the comments from memory. */
for (i = 0; i <= CMNT_LAST; i++) LeadImage1->Comment[i] = Empty;
}