LoadInfo... example for C++ Builder

Take the following steps to exercise the LoadInfo event and LoadInfo... properties. The example creates a raw FAX file, and 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.h file, include this file:

 #include "LTRASTERPROCLib_TLB.h"

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.h Private declaration section:

 int MyInfoBits;
int MyInfoFlags;
int MyInfoFormat;
float MyInfoHeight;
long MyInfoOffset;
float MyInfoWidth;
int MyInfoXRes;
int MyInfoYRes;
LEADRasterIO * pMyRasterIO;

7.

Add the following to LoadLead Click’s Procedure:

  CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO, (void**)&pMyRasterIO);
LEADEventSink1->Connect (pMyRasterIO, DIID__LEADRasterIOEvents);

8.

Code the Close event procedure as follows:

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
 if(pMyRasterIO)
  pMyRasterIO->Release();
}

9.

image\btncmd.gif Add a button to your form and name it as follows:

 

Name

Caption

 

Button1

Button1

10.

Code the Button1 click’s procedure as follows:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 LEADRasterProcess * pRasterProc;

CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL, IID_ILEADRasterProcess, (void**)&pRasterProc);
LEADRasterView1->ScaleMode = 3; //Pixels
//Make the image look OK as a 1-bit image.
pRasterProc->Size (LEADRasterView1->Raster,
LEADRasterView1->ScaleWidth,
LEADRasterView1->ScaleHeight, RESIZE_RESAMPLE);
pRasterProc->Halftone (LEADRasterView1->Raster, HALFTONE_VIEW, 45);
 pRasterProc->Release ( ) ;
//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.
pMyRasterIO->Save (LEADRasterView1->Raster, AnsiToOLESTR("c:\\temp\\tmp.tif"), FILE_FAX_G3_2D,
1, (QFactorConstants)1, SAVE_OVERWRITE);

pMyRasterIO->Load (LEADRasterView1->Raster, AnsiToOLESTR("c:\\temp\\tmp.tif"), 0, 0, 1);
//Repaint the newly loaded image.
LEADRasterView1->ForceRepaint ();
}

11.

Code the pMyRasterIO object's LoadInfo event as follows:

void __fastcall TForm1:: LEADEventSink1Invoke(TObject *Sender, int DispID,
const TGUID &IID, int LocaleID, WORD Flags, tagDISPPARAMS &Params,
Pointer varResult, Pointer ExcepInfo, Pointer ArgErr)
{
switch (DispID)
{
 case LEADRASTERIOEVENTS_LOADINFO:
{
 pMyRasterIO->LoadInfoBits =(short) MyInfoBits;
pMyRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)MyInfoFlags;
pMyRasterIO->LoadInfoFormat =(RasterFileConstants) MyInfoFormat;
pMyRasterIO->LoadInfoHeight = MyInfoHeight;
pMyRasterIO->LoadInfoOffset = MyInfoOffset;
pMyRasterIO->LoadInfoWidth = MyInfoWidth;
pMyRasterIO->LoadInfoXRes = MyInfoXRes;
pMyRasterIO->LoadInfoYRes = MyInfoYRes;
}
break;
}
}

12.

Run your program to test it.