LoadInfo... example for Delphi
Take the following steps to exercise the LoadInfo event and LoadInfo... properties. The example creates a raw FAX file, then loads the file it just created. (Getting format information from an unfamiliar file is beyond the scope of this example.)
1. |
Start with the project that you created in Loading and Displaying an Image. |
2. |
On the Project pull-down menu, use the Import Type library… and select the LEAD Raster Process object library (14.5). |
3. |
At the beginning of the Unit1 file, add LTRASTERPROCLib_TLB to the uses section. For example: |
Uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, LTRASTERPROCLib_TLB;
4. |
If you didn’t install LEvntSnk, install it. |
|
On the Component pull-down menu, use install component …, and browse to LEADXX\Include\LEvntSnk.pas, and press Ok. |
5. |
From the ActiveX controls, Add the LEvntSnk control to your form. |
6. |
Add the following variables to Unit1 Private declaration section: |
MyInfoBits: Integer;
MyInfoFlags: Longint;
MyInfoFormat: Integer;
MyInfoHeight: Single;
MyInfoOffset: Longint;
MyInfoWidth: Single;
MyInfoXRes: Integer;
MyInfoYRes: Integer;
MyRasterIO: LEADRasterIO;
7. |
Add the following to LoadLead Click’s Procedure: |
MyRasterIO:= CreateComObject (CLASS_LEADRasterIO) as ILEADRasterIO;
LEADEventSink1.Connect (MyRasterIO, _LEADRasterIOEvents);
8. |
|
|
|
Name |
Caption |
|
Button1 |
Button1 |
9. |
Code the Button1 click’s procedure as follows: |
procedure TForm1.Button1Click(Sender: TObject);
var
sRet: Smallint;
RasterProc: LEADRasterProcess;
begin
RasterProc:= CreateComObject (CLASS_LEADRasterProcess) as LEADRasterProcess;
LEADRasterView1.ScaleMode := 3; //Pixels
//Make the image look OK as a 1-bit image.
RasterProc.Size (LEADRasterView1.Raster,
LEADRasterView1.ScaleWidth,
LEADRasterView1.ScaleHeight, RESIZE_RESAMPLE);
RasterProc.Halftone (LEADRasterView1.Raster, HALFTONE_VIEW, 45);
//Set the form-level variables to the values we will use when loading.
MyInfoBits := 1;
MyInfoFlags := LOADINFO_TOPLEFT;
MyInfoFormat := FILE_FAX_G3_2D;
MyInfoHeight := LEADRasterView1.Raster.BitmapHeight;
MyInfoOffset := 0;
MyInfoWidth := LEADRasterView1.Raster.BitmapWidth;
MyInfoXRes := LEADRasterView1.Raster.BitmapXRes;
MyInfoYRes := LEADRasterView1.Raster.BitmapYRes;
//Save the image as raw FAX; then load the saved file.
//Format information will be supplied in the LoadInfo event.
MyRasterIO.Save (LEADRasterView1.Raster, 'c:\temp\tmp.tif', FILE_FAX_G3_2D,
1, 1, SAVE_OVERWRITE);
MyRasterIO.Load (LEADRasterView1.Raster, 'c:\temp\tmp.tif', 0, 0, 1);
//Repaint the newly loaded image.
LEADRasterView1.ForceRepaint (sRet);
end;
10. |
Code the MyRasterIO object's LoadInfo event as follows: |
procedure TForm1. LEADEventSink1Invoke(Sender: TObject; DispID: Integer;
const IID: TGUID; LocaleID: Integer; Flags: Word; Params: tagDISPPARAMS;
varResult, ExcepInfo, ArgErr: Pointer);
begin
case (DispID) of
LEADRASTERIOEVENTS_LOADINFO:
begin
MyRasterIO.LoadInfoBits := MyInfoBits;
MyRasterIO.LoadInfoFlags := MyInfoFlags;
MyRasterIO.LoadInfoFormat := MyInfoFormat;
MyRasterIO.LoadInfoHeight := MyInfoHeight;
MyRasterIO.LoadInfoOffset := MyInfoOffset;
MyRasterIO.LoadInfoWidth := MyInfoWidth;
MyRasterIO.LoadInfoXRes := MyInfoXRes;
MyRasterIO.LoadInfoYRes := MyInfoYRes;
end;
end;
end;
11. |
Run your program to test it. |