📄 prints.pas
字号:
unit prints;
interface
uses
Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls, ExtDlgs, Dialogs,printers,jpeg;
type
tprintthread=class(tthread)
private
i:integer;
protected
procedure execute;override;
public
constructor create();
end;
implementation
uses pic;
constructor tprintthread.create();
begin
inherited create(false);
end;
procedure tprintthread.execute;
var
prnrect,imagrect:trect;
centerx,centery,x1,y1,x2,y2:integer;
pheight,pwidth:integer;
destrect,sourect:trect; bt,bt1:Tbitmap;
begin
pheight:=printer.pageheight;
pwidth:=printer.pagewidth;
destrect.Top:=0;
destrect.Left:=0;
if pheight>round((OKBottomDlg5.image1.Picture.Height*pwidth)/OKBottomDlg5.image1.Picture.Width) then
begin
DestRect.Right:=pwidth;
DestRect.Bottom:=round((OKBottomDlg5.image1.Picture.Height*pwidth)/OKBottomDlg5.image1.Picture.Width);
end
else
begin
DestRect.Right:=round((OKBottomDlg5.image1.Picture.Width*pheight)/OKBottomDlg5.image1.Picture.Height) ;
destrect.Bottom:=pheight;
end;
bt:=Tbitmap.Create();
bt1:=Tbitmap.Create();
bt.Canvas.Lock;
bt1.Canvas.Lock;
try
bt.PixelFormat:=pf24bit;
bt.Width:=OKBottomDlg5.image1.Picture.Width;
bt.Height:=OKBottomDlg5.image1.Picture.Height;
bt.Assign(OKBottomDlg5.image1.Picture.Graphic);
bt1.PixelFormat:=pf24bit;
bt1.Width:=DestRect.Right;
bt1.Height:=destrect.Bottom;
bt1.Canvas.StretchDraw(destrect,bt);
finally
bt.Canvas.Unlock;
bt.Free;
end;
try
with bt1 do
begin
try
printer.begindoc;
centerx:=pwidth div 2;
centery:=pheight div 2;
x1:=centerx-(DestRect.Right div 2);
y1:=centery-(destrect.Bottom div 2);
x2:=centerx+(DestRect.Right div 2);
y2:=centery+(destrect.Bottom div 2);
prnrect:=rect(x1,y1,x2,y2);
imagrect:=rect(0,0,bt1.Width,bt1.Height);
printer.Canvas.CopyRect(prnrect,bt1.Canvas,imagrect);
printer.EndDoc;
except
application.MessageBox('打印终止','提示',mb_ok);
end;
end;
finally
bt1.Canvas.Unlock;
bt1.Free;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -