Sign in Join
Wiki copytemporary

Print Bitmap/ru

English · Français · Русский

Как отправить изображение на принтер

pascal
// uses Printers; // необходимо подключить модуль
var
  Scale :LongInt;
begin
  with Printer do
    begin
      BeginDoc;
      Scale := Min(
        Printer.PageWidth div Image1.Picture.Bitmap.Width,
        Printer.PageHeight div Image1.Picture.Bitmap.Height);

      Printer.Canvas.StretchDraw(
        Rect(0, 0, Image1.Picture.Bitmap.Width*Scale, Image1.Picture.Bitmap.Height*Scale),
        Image1.Picture.Bitmap);

      EndDoc;
    end;
end;

Печать jpeg картинки с масштабированием через Bitmap на лист А4

pascal
// uses Printers; // необходимо подключить модуль
procedure PrintImage(Image: TImage);
var
  TempImageBMP: Graphics.TBitmap;
  TempImageJPEG: TImage;
  ScaleX, ScaleY: Double;
  RectLeft,RectTop,RectRight,RectBottom: Integer;
begin

TempImageBMP := Graphics.TBitmap.Create;
TempImageBMP.Assign(Image.Picture.Graphic);
TempImageJPEG := TImage.Create(Self);
TempImageJPEG.Picture.Bitmap := TempImageBMP;

Printer.BeginDoc;
// Расчет соотношение сторон
ScaleX := Printer.PageWidth / TempImageJPEG.Picture.Bitmap.Width;
ScaleY := Printer.PageHeight / TempImageJPEG.Picture.Bitmap.Height;

RectLeft:=0;
RectTop:=0;
RectRight := trunc(TempImageJPEG.Picture.Bitmap.Width * scaleX);
RectBottom := trunc(TempImageJPEG.Picture.Bitmap.Height * scaleY);
Printer.Canvas.StretchDraw(
        Rect(RectLeft,RectTop,RectRight,RectBottom),
        TempImageJPEG.Picture.Bitmap);
Printer.EndDoc;

TempImageBMP.Free;
TempImageJPEG.Free;
end;

From the Free Pascal wiki, page "Print Bitmap/ru", as it stood on 2020-02-23 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.