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.
var
MyCommentText: String; //String for CMNT_SZDESC
FilePath: String; //File to be updated
i: Longint; //Loop counter and array index
RasterIO: LEADRasterIO;
RasterProc: LEADRasterProcess;
RasterVarEmpty: LEADRasterVariant;
RasterVar: LEADRasterVariant;
begin
RasterIO:= CreateComObject (CLASS_LEADRasterIO) as LEADRasterIO;
RasterProc:= CreateComObject (CLASS_LEADRasterProcess ) as LEADRasterProcess;
RasterVarEmpty:= coLEADRasterVariant.Create ( );
RasterVar:= coLEADRasterVariant.Create ( );
//Specify the file that we will update.
FilePath := 'c:\temp\Test.tif';
//Get all of the current comments from the file.
//Temporarily disable method errors so that we do not fail when comments are missing.
RasterIO.EnableMethodErrors := False;
for i := 0 to CMNT_LAST do
begin
RasterIO.Comment[i]:= RasterVarEmpty;
RasterIO.Comment[i]:= RasterIO.ReadComment(LEADRasterView1.Raster, FilePath, 1, i);
end;
//Load and modify the image.
RasterIO.EnableMethodErrors := False;
RasterIO.Load (LEADRasterView1.Raster, FilePath, 0, 0, 1);
RasterProc.Reverse (LEADRasterView1.Raster);
//Update the CMNT_SZDESC comment.
MyCommentText := Chr(13) + 'This image has been reversed.';
RasterVar.Type_:= VALUE_STRING;
RasterVar:= RasterIO.Comment[CMNT_SZDESC];
RasterVar.StringValue:= RasterVar.StringValue + MyCommentText;
RasterIO.Comment[CMNT_SZDESC]:= RasterVar;
//Save the file and read the comment that we saved.
RasterIO.Save (LEADRasterView1.Raster, FilePath, FILE_TIF, LEADRasterView1.Raster.BitmapBits, 0, SAVE_OVERWRITE);
RasterVar:= RasterIO.ReadComment (LEADRasterView1.Raster, FilePath, 1, CMNT_SZDESC);
//Display the message
ShowMessage (RasterVar.StringValue);
//Clear the comments from memory
for i := 0 to CMNT_LAST do
RasterIO.Comment [i]:= RasterVarEmpty;
end;