Loading and Displaying an Image (Delphi)

Take the following steps to start a project and to add some code that positions, scales, and displays an image on the main form:

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.

image\btnlead.gif Select the LEAD Main control on the VCL toolbar. Size and position the control as you want it to appear at run time, and change the name of the control to Lead1.

5.

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

 

Name

Caption

LoadLead

Load Image

 

6.

Code the main form's FormShow procedure as follows. In online help, you can copy the block of code and paste it into your application.

procedure TForm1.FormShow(Sender: TObject);

begin

  { Set defaults for displaying the image. }
  { These are all persistent properties that can be set in the properties box. }
  Lead1.BorderStyle := bsSingle;
  Lead1.BackColor := RGB(255, 255, 125);
  Lead1.PaintDither := pdDiffusion;
  Lead1.PaintPalette := ppAuto;
  Lead1.AutoRepaint := True;
  Lead1.AutoSize := False;
  Lead1.AutoSetRects := True;
  Lead1.PaintSizeMode := smFit;

end;

7.

Code the LoadLead button's click procedure as follows:

procedure TForm1.LeadLoadClick(Sender: TObject);
begin
    Lead1.Load('c:\lead\images\image1.cmp', 0, 0, 1);
end;

8.

At the beginning of the Unit1 file, add LEADUNT to the uses section. In order to use the constants in Delphi, you must add the LEADDEF unit to the uses section. For example:

 

 

uses

 

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, LEADVCL, StdCtrls, LEADDEF

 

9.

Run your program to test it.

10.

Save the project to use as a starting point for other tasks in this tutorial.