FilePage Event Example for Delphi
This example shows how the FilePage event can be used to size and position a RasterView Control when an image is loaded.
//Use Load to load an image
procedure TForm1.Button1Click(Sender: TObject);
begin
RasterIO:= CreateComObject(CLASS_LEADRasterIO) as LEADRasterIo;
LEADEventSink1.Connect (RasterIO, _LEADRasterIOEvents);
RasterIO.Load (LEADRasterView1.Raster, 'v:\images\24bit.bmp', 0, 1, 1);
end;
procedure TForm1. LEADEventSink1Invoke(Sender: TObject; DispID: Integer;
const IID: TGUID; LocaleID: Integer; Flags: Word; Params: tagDISPPARAMS;
varResult, ExcepInfo, ArgErr: Pointer);
var
HeightFactor, WidthFactor: Single; // Factors for aspect ratio
HeightAllowed, WidthAllowed: Single; // Maximum width and height
begin
case (DispID) of
LEADRASTERIOEVENTS_FILEPAGE:
begin
// Set the variables used for preserving the aspect ratio.
//Allow for a border of 1/8 of the form size.
//The units of measure do not matter, since we are calculating proportions.
HeightFactor:= RasterIO.InfoHeight;
WidthFactor:= RasterIO.InfoWidth;
HeightAllowed:= ClientHeight * 3 / 4;
WidthAllowed:= ClientWidth * 3 / 4;
//Center the LEAD RasterView control on the form, preserving the aspect ratio.
//Check to see if using the maximum width will make the image too tall.
//Set the dimensions based on the result.
if (((WidthAllowed * HeightFactor) / WidthFactor) < HeightAllowed) then
begin
LEADRasterView1.Left:= Trunc(ClientWidth / 8);
LEADRasterView1.Width:= Trunc(WidthAllowed);
LEADRasterView1.Height:= Trunc((LEADRasterView1.Width * HeightFactor) / WidthFactor);
LEADRasterView1.Top:= Trunc((ClientHeight - LEADRasterView1.Height) / 2);
end
else
begin
LEADRasterView1.Top:= Trunc(ClientHeight / 8);
LEADRasterView1.Height:= Trunc(HeightAllowed);
LEADRasterView1.Width := Trunc((LEADRasterView1.Height * WidthFactor) / HeightFactor);
LEADRasterView1.Left := Trunc((ClientWidth - LEADRasterView1.Width) / 2);
end;
// Set the image display size to match the LEAD RasterView control.
LEADRasterView1.AutoScroll := False;
LEADRasterView1.AutoSetRects := True;
LEADRasterView1.AutoRepaint := True;
LEADRasterView1.PaintSizeMode := PAINTSIZEMODE_FIT;
end;
end;
end;