PaintWhileLoad example for Delphi
This example causes the LEAD control to paint the image as it loads.
procedure TForm1.Button3Click(Sender: TObject);
var
HeightFactor, WidthFactor, HeightAllowed, WidthAllowed: Single;
ImageHeight, ImageWidth, BitmapHeight, BitmapWidth: integer;
begin
Lead1.PaintWhileLoad := True;
{Get information about the image so that we can size the control.}
Lead1.GetFileInfo('c:\lead\images\image2.cmp', 0);
{Set the variables used for preserving the aspect ratio.}
{Allow for a border of 1/8 of the form size.}
HeightFactor := Lead1.InfoHeight;
WidthFactor := Lead1.InfoWidth;
HeightAllowed := ClientHeight * 3/4;
WidthAllowed := ClientWidth * 3/4;
{Center the LEAD 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
Lead1.Left := round(ClientWidth / 8);
Lead1.Width := round(WidthAllowed);
Lead1.Height := round((Lead1.Width * HeightFactor) / WidthFactor);
Lead1.Top := round((ClientHeight - Lead1.Height) / 2);
end
Else
begin
Lead1.Top := round(ClientHeight / 8);
Lead1.Height := round(HeightAllowed);
Lead1.Width := round((Lead1.Height * WidthFactor) / HeightFactor);
Lead1.Left := round((ClientWidth - Lead1.Width) / 2);
End;
{Set the image display sizes}
ImageHeight := Lead1.Height;
ImageWidth := Lead1.Width;
BitmapHeight := Lead1.InfoHeight;
BitmapWidth := Lead1.InfoWidth;
Lead1.SetSrcRect(0, 0, BitmapWidth, BitmapHeight);
Lead1.SetSrcClipRect(0, 0, BitmapWidth, BitmapHeight);
Lead1.SetDstRect(0, 0, ImageWidth, ImageHeight);
Lead1.SetDstClipRect(0, 0, ImageWidth, ImageHeight);
{Turn off the automatic adjustment of display rectangles}
Lead1.AutoSetRects := False;
{Load the file}
Lead1.Load('c:\lead\images\image2.cmp', 0, 0, 1);
{Turn on the automatic adjustment of display rectangles for future use}
Lead1.AutoSetRects := True;
end;