Loading and Displaying an Image (Delphi 6.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 6.0.

2.

If you didn’t install LEAD Raster View Control, install it as follows:

 

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

3.

Select LEAD Raster View control and add it to your main form. Size and position the control, as you want it to appear at run time.

4.

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

5.

Select LEAD Raster IO, from the ActiveX tab and add it to your form.

6.

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

7.

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

 

Name

Caption

 

btnLoadImage

Load Image

8.

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;

9.

Code the btnLoadImage button's click procedure as follows:

procedure TForm1.btnLoadImageClick(Sender: TObject);
begin
   LEADRasterIO1.Load ( LEADRasterView1.Raster, 'v:\images\Image1.cmp', 0, 0, 1 ) ;
end;

10.

Run your program to test it.

11.

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