你首先将PaintBox绘制的图形这样处理 :
var
bmp :TBitmap;
begin
bmp :=TBitmap.Create;
bmp.Width :=PaintBox.Width;
bmp.Height :=PaintBox.Height;
BitBlt(bmp.Canvas.Handle,0,0,bmp.Width,bmp.Height,PaintBox.Canvas.Handle,0,0,SRCCOPY);
Image.AutoSize :=True;
Image.Picture.Bitmap.Assign(bmp);
bmp.Free;
end;
打印:
var
ScaleX,ScaleY :Integer;
R :TRect;
begin
if Printer.Printers.Count=0 then
begin
ShowMessage('请首先安装打印机');
Exit; //跳出N11Click
end;
if not PrintDialog.Execute then Exit
else
begin
with Printer do
begin
BeginDoc;
ScaleX :=GetDeviceCaps(Handle,LogPixelsX) div PixelsPerInch;
ScaleY :=GetDeviceCaps(Handle,LogPixelsY) div PixelsPerInch;
R :=Rect(0,0,Image.Width*ScaleX,Image.Height*ScaleY);
Canvas.StretchDraw(R,Image.Picture.Graphic);
EndDoc;
end;
end;
end;