FMXPrinting (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to print an image from a FireMonkey application. This example consists of a form, a button, and an image. When you press the button, the image is printed to the attached printer, with the specified printing resolution (DPI).

Please refer to the Printing from a FireMonkey Application topic for more information regarding printing in FireMonkey applications.

Code

procedure TMyForm.PrintButtonClick(Sender: TObject);
var
  SrcRect, DestRect: TRectF;

begin
  { Set the default DPI for the printer. The SelectDPI routine defaults
    to the closest available resolution as reported by the driver. }
  Printer.ActivePrinter.SelectDPI(1200, 1200);

  { Set canvas filling style. }
  Printer.Canvas.Fill.Color := claBlack;
  Printer.Canvas.Fill.Kind := TBrushKind.Solid;

  { Start printing. }
  Printer.BeginDoc;

  { Set the Source and Destination TRects. }
  SrcRect := Image1.LocalRect;
  DestRect := TRectF.Create(0, 0, Printer.PageWidth, Printer.PageHeight);

  { Print the picture, on all the surface of the page and all opaque. }
  Printer.Canvas.DrawBitmap(Image1.Bitmap, SrcRect, DestRect, 1);

  { Finish the printing job. }
  Printer.EndDoc;
end;

Uses

See Also