Loading and Displaying an Image (Delphi 4.0)

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

1.

Start Delphi 4.0.

2.

If you didn’t install LEAD RasterView Control, install it.

 

On the Component pull-down menu, use the Import ActiveX Control… and select the LEAD RasterView Control (14.5), and Press install.

3.

image\btnlead.gif Select the LEAD RasterView control; then add the control to your main form. Size and position the control, as you want it to appear at run time.

4.

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

 

Name

Caption

 

LoadLead

Load Image

5.

Code the main form's Create procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

procedure TForm1.FormCreate(Sender: TObject);
begin
  //Set defaults for displaying the image.
  //These are all persistent properties that can be set in the properties box.
  LEADRasterView1.Appearance := RASTERVIEW_APPEARANCE_FLAT;
  LEADRasterView1.BorderStyle := 1;
  LEADRasterView1.BackColor := RGB(255, 255, 125);
  LEADRasterView1.PaintDither := PAINTDITHER_DIFFUSION;
  LEADRasterView1.PaintPalette:= PAINTPALETTE_AUTO;
  LEADRasterView1.AutoRepaint := True;
  LEADRasterView1.AutoSize := False;
  LEADRasterView1.AutoSetRects := True;
  LEADRasterView1.PaintSizeMode := PAINTSIZEMODE_FIT;
  LEADRasterView1.EnableFireMouse2Event:= true;
end;

6.

Code the LoadLead button's click procedure as follows:

procedure TForm1.LoadLeadClick(Sender: TObject);
var
   RasterIO: ILEADRasterIO;
begin
   RasterIO := CreateComObject (CLASS_LEADRasterIO) as ILEADRasterIO;
   RasterIO.Load ( LEADRasterView1.Raster, 'v:\images\Image1.cmp', 0, 0, 1 ) ;
end;

7.

On the Project pull-down menu, use the Import Type library… and select the LEAD Raster IO object library (14), and Press Ok.

8.

At the beginning of the Unit1 file, add ComObj, LTRASTERLib_TLB, and LTRASTERIOLib_TLB to the uses section to handle Com objects, use the constants in Delphi, and handle the Raster IO object library. For example:

Uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComObj, LTRASTERLib_TLB, LTRASTERIOLib_TLB;

9.

Run your program to test it.

10.

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