Comment example for Delphi
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. |
procedure TForm1.ReadComment1Click(Sender: TObject);
var
Empty: Variant; { For clearing comments }
MyCommentText: string; { String for CMNT_SZDESC }
NewCommentText: string; { String for CMNT_SZDESC that we read }
FilePath: string; { File to be updated }
i: Integer; { Counter }
nRet: Integer;
begin
{ Specify the file that we will update. }
FilePath := 'e:\image1.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 to CMNT_LAST do
begin
LeadImage1.Comment[i] := Empty;
LeadImage1.Comment[i] := LeadImage1.ReadComment(FilePath, 0, i);
end;
LeadImage1.EnableMethodErrors := True;
{ Load and modify the image. }
nRet:= LeadImage1.Load(FilePath, 0, 0, 1);
if(nRet = SUCCESS)then
begin
LeadImage1.Reverse();
{ Update the CMNT_SZDESC comment. }
MyCommentText := CHR(13) + 'This 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(PChar(NewCommentText), 'File Comments', mb_OK);
{ Clear the comments from memory. }
for i := 0 To CMNT_LAST do
LeadImage1.Comment[i] := Empty;
end;
end;