RenderCenter example for Delphi
procedure TForm1.Button1Click(Sender: TObject);
var
{Declare the variables for print-area measurements.}
SkipSpace: Integer;
UsableWidth, UsableHeight, MaxImageHeight: Single;
{Declare the variables for sizing and positioning the image.}
PrintHeight, PrintWidth: Integer;
{Declare variables used for preserving aspect ratios.}
WidthFactor, HeightFactor: Single;
begin
{Set the variables used for preserving the aspect ratio}
HeightFactor := LEADImage1.BitmapHeight;
WidthFactor := LEADImage1.BitmapWidth;
{Set the pointer to an hourglass}
Screen.Cursor := crHourglass;
{Establish some print-area dimensions. These are arbitrary values.}
SkipSpace := round(Printer.PageHeight / 30);
UsableWidth := round(Printer.PageWidth) - (SkipSpace * 4);
UsableHeight := round(Printer.PageHeight) - (SkipSpace * 4);
{Get the maximum height of one image,}
{assuming two equal-size images and space between them.}
MaxImageHeight := round( (UsableHeight - (2 * SkipSpace)) / 2);
{Size and position the first image, 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 ((UsableWidth * HeightFactor) / WidthFactor) < MaxImageHeight Then
begin
PrintWidth := Round(UsableWidth);
PrintHeight := Round((PrintWidth * HeightFactor) / WidthFactor);
end
Else
begin
PrintHeight := Round(MaxImageHeight);
PrintWidth := Round((PrintHeight * WidthFactor) / HeightFactor);
End;
{Start Printing}
Printer.BeginDoc;
{ Set the RenderCenter property to False, so we can print the image starting from the point (0, 0)}
LEADImage1.RenderCenter := False;
{Print the Image}
LEADImage1.Render( Printer.Canvas.HANDLE, 0, 0, PrintWidth, PrintHeight );
{End Printing}
Printer.EndDoc;
{Set the mouse pointer back to the default}
Screen.Cursor := crDefault;
end;