image控件的打印图片,没有结果。(100分)

  • 主题发起人 酸橙子
  • 开始时间

酸橙子

Unregistered / Unconfirmed
GUEST, unregistred user!
那位大虾能帮帮忙,看看下面的代码有什么问题。打印没有出任何结果。调试的时候也曾经试过newbmp读一个
*.bmp文件,打印是成功的。但是经过newbmp.Canvas.CopyRect语句之后,再Printer.Canvas.StretchDraw就
没有结果了。真是头大啊!
newbmp:= TBitmap.Create;
newbmp.Width:=img_main.Width;
newbmp.Height:=img_main.Height;
bmpheight:=img_main.Height;
bmpwidth:=img_main.Width;
newbmp.Canvas.CopyRect(rect(0,0,bmpwidth,bmpheight),img_main.Canvas,rect(0,0,bmpwidth,bmpheight));
Printer.Canvas.StretchDraw(rect(0,2900,4700,6600),newbmp);
newbmp.free;
或者有什么别的好方法解决这个问题。
 
Delphi文本和图形的打印方法

一、基本知识
1、在代码单元的Uses部分增加Printers,打印实际上是把要打印的内容画到tprinter的canvas画布上。
2、选择输出的打印机:printdialog1.execute
3、选择打印控制选项 printersetupdialog1.execute;

二、打印文本
//打印Memo1中的内容
procedure TForm1.BitBtn1Click(Sender: TObject);
var
lines:integer;
prntext:text;
定义打印文本变量
begin

if printdialog1.execute then

assignprn(prntext);
//将prntext文件分配给打印机
rewrite(prntext);
//打开prntext文件
printer.canvas.font:=memo1.font;
//设置打印对象的canvas的字体
for lines:=0 to memo1.lines.count-1do

writeln(prntext
memo1.lines[lines]);
//把Memo1的内容写到打印机对象
system.close(prntext);
//关闭打印文件
end;

三、打印图形
1、利用打印机的分辨率,图形将打印在页面的左上角,图形较小。
procedure TForm1.BitBtn1Click(Sender: TObject);
begin

if printdialog1.execute then

begin

printer.begin
doc;
printer.canvas.draw(0
0
image1.picture.graphic);
printer.enddoc;
end;

end;

2、利用打印机画布canvas的stretchdraw方法
可以对图形进行更为灵活的处理。
其中要用到一个代表图形输出区域的Rect参数
Trect的类型定义如下:
TRect = record
case Integer of
0: (Left
Top
Right
Bottom: Integer);
1: (TopLeft
BottomRight: TPoint);
end;
 

例:通过调整Rect的范围、图形大小及其在打印页面上的位置,实现图形打印:
procedure TForm1.Button1Click(Sender: TObject);
var strect:Trect;
//定义打印输出矩形框的大小
temhi
temwd:integer;
begin

if printdialog1.execute then

begin

temhi:=image1.picture.height;
temwd:=image1.picture.width;
while (temhi<printer.pageheight div 2) and //将图形放大到打印页面的1/2 (temwd<printer.pagewidth div 2)do
begin

temhi:=temhi+temhi;
temwd:=temwd+temwd;
end;

with strectdo
//定义图形在页面上的中心位置输出
begin

left:=(printer.pagewidth -temwd) div 2;
top:=(printer.pageheight-temhi) div 2;
right:=left+temwd;
bottom:=top+temhi;
end;

with Printerdo
begin

begin
doc;
//将放大的图形向打印机输出
canvas.stretchdraw(strect
image1.picture.graphic);
enddoc;
end;

end;

end;
 

Similar threads

I
回复
0
查看
582
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
727
import
I
顶部