Comment example for Visual J++

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.

// Specify the file that we will update.
String strFilePath = "d:\\lead\\images\\testcmt.tif";

// Get all of the current comments from the file.
// Temporarily disable method errors so that we do not fail when comments are missing.
LEAD1.setEnableMethodErrors( false );
for( short i = 0 ; i < LTOCXU.CommentConstants.CMNT_LAST ; i ++ )
{
   LEAD1.setComment( i, new Variant() );
   LEAD1.setComment( i, LEAD1.ReadComment( strFilePath, (short) 0, i ) );
}
LEAD1.setEnableMethodErrors( true );

// Load and modify the image.
LEAD1.Load( strFilePath, (short) 0, (short) 0, (short) 1 );
LEAD1.Reverse();

// Update the CMNT_SZDESC comment.
String strMyComment = "This image has been reversed.";
String strOldComment = LEAD1.getComment( (short) LTOCXU.CommentConstants.CMNT_SZDESC ).toString() ;
String strTempComment = strOldComment + strMyComment;
LEAD1.setComment( (short) LTOCXU.CommentConstants.CMNT_SZDESC, new Variant( strTempComment ) ); 

// Save the file and read the comment that we saved.
LEAD1.Save( strFilePath, (short) LTOCXU.FileConstants.FILE_TIF, LEAD1.getBitmapBits(), (short) 0, (short) LTOCXU.SaveModifyConstants.SAVE_OVERWRITE );
String strNewComment = LEAD1.ReadComment( strFilePath, (short) 0, (short) LTOCXU.CommentConstants.CMNT_SZDESC ).toString();

// Display the message
MessageBox.show( strNewComment );

// Clear the comments from memory
for( short i = 0 ; i < LTOCXU.CommentConstants.CMNT_LAST ; i++ )
   LEAD1.setComment( i, new Variant() );