Zooming In on a Selection (Delphi 4.0)

Take the following steps to add code that lets you select an area with a mouse, and zoom in on the selected area.

1.

Start with the project that you created in Loading and Displaying an Image.

2.

Handle the LEADRasterView1 control's OnMouseDown2 event, and code LEADRasterView1MouseDown2 as follows. This code selects a different drawing object each time the event occurs.

procedure TForm1.LEADRasterView1MouseDown2(Sender: TObject; Button, 
  Shift: Smallint; x, y: Integer);
 begin
   //Enable AutoRubberBand   
   LEADRasterView1.AutoRubberBand := True;
   LEADRasterView1.MousePointer := 2;
end;

3.

Code the LEADRasterView1 control's Rubberband procedure, as the following:

procedure TForm1.LEADRasterView1RubberBand(Sender: TObject);
var
   zoomleft: Integer;
     zoomtop: Integer;
     zoomwidth: Integer;
   zoomheight: Integer;
   Ret: Smallint;
begin
   LEADRasterView1.MousePointer := 0;
   //Zoom in on the selection.
   zoomleft := Trunc (LEADRasterView1.RubberBandLeft);
   zoomtop := Trunc (LEADRasterView1.RubberBandTop);
   zoomwidth := Trunc (LEADRasterView1.RubberBandWidth);
   zoomheight := Trunc (LEADRasterView1.RubberBandHeight);
   //Zoom in on the rectangle defined by the rubberband
   LEADRasterView1.ZoomToRect (  zoomleft, zoomtop, zoomwidth, zoomheight, Ret);
   LEADRasterView1.Refresh() ;
end;

4.

Run your program to test it.