Combining Images with Regions (Delphi)

1.

Start Delphi.

2.

In the File menu, choose New Application.

3.

On the Delphi toolbar, click the LEADTOOLS tab. If you have used a LEAD VCL control before, the icon appears on the toolbar. Otherwise, refer to Installing VCL before continuing with this tutorial.

4.

Add 2 of the LEAD Main VCL controls to your form. Size and position the controls, as you want them to appear at run time.

5.

Add a button to your form and name it as follows:

 

Name

Caption

 

btnCombine

Combine

6.

Handle the Form1 OnCreate event, and code FormCreate as follows:

procedure TForm1.FormCreate(Sender: TObject);
begin
   LEADImage1.Load( 'r:\images\image1.cmp', 0, 1, 1 ) ;
   LEADImage2.Load ( 'r:\images\image2.cmp', 0, 1, 1 ) ;
end;

7.

Handle the btnCombine button's OnClick event, and code the btnCombineClick procedure as follows:

procedure TForm1.btnCombineClick(Sender: TObject);
var
   nDstLeft : Integer; 
   nDstTop : Integer; 
   nSrcLeft : Integer; 
   nSrcTop  : Integer; 
   nDstWidth : Integer;
   nDstHeight : Integer;
   rClientArea : TRect;
begin
   Windows.GetClientRect ( LEADImage1.Handle, rClientArea );
   LEADImage1.SetRgnRect ( Trunc(rClientArea.right/8), Trunc(rClientArea.bottom/8), Trunc(rClientArea.right/2), Trunc(rClientArea.bottom/2), L_RGN_SET);

   nDstLeft := Trunc(LEADImage1.BitmapWidth /8 );
   nDstTop := Trunc(LEADImage1.BitmapHeight /8 );
   nDstWidth := Trunc(LEADImage1.BitmapWidth );
   nDstHeight := Trunc(LEADImage1.BitmapHeight );
   nSrcLeft := 0;
   nSrcTop := 0;

   LEADImage1.Combine ( nDstLeft, nDstTop, nDstWidth, nDstHeight, LEADImage2.Bitmap, nSrcLeft, nSrcTop, CB_OP_ADD + CB_DST_0);
end;

8.

At the beginning of the Unit1 file, add LEADDef to the uses section.

9.

Run your program to test it.