procedure Tdyform.BitBtn1Click(Sender: TObject); var px,py:integer; rect:trect; begin //showmessage(inttostr(screen.PixelsPerInch)); inherited; try //获得打印机的分辨率 px:=getdevicecaps(printer.Handle,logpixelsx); py:=getdevicecaps(printer.Handle,logpixelsy); //设置图片的打印区域 with rect do begin left:=trunc(strtofloat(edit1.Text)/2.54*px); top:=trunc(strtofloat(edit2.Text)/2.54*py); right:=trunc(image1.Picture.Width*px*strtofloat(edit3.text)/100)+left; bottom:=trunc(image1.Picture.Height*py*strtofloat(edit3.text)/100)+top; end; //向打印机输出图片 with image1.Picture.Bitmap do begin printer.Title:='图片打印'; try printer.begindoc; printer.canvas.StretchDraw(rect,image1.Picture.Bitmap); application.ProcessMessages; printer.enddoc; except printer.Abort; raise; end; end; except showmessage('没有打印机,请选择打印机!'); end; end;
var
px,py:integer;
rect:trect;
begin
//showmessage(inttostr(screen.PixelsPerInch));
inherited;
try
//获得打印机的分辨率
px:=getdevicecaps(printer.Handle,logpixelsx);
py:=getdevicecaps(printer.Handle,logpixelsy);
//设置图片的打印区域
with rect do
begin
left:=trunc(strtofloat(edit1.Text)/2.54*px);
top:=trunc(strtofloat(edit2.Text)/2.54*py);
right:=trunc(image1.Picture.Width*px*strtofloat(edit3.text)/100)+left;
bottom:=trunc(image1.Picture.Height*py*strtofloat(edit3.text)/100)+top;
end;
//向打印机输出图片
with image1.Picture.Bitmap do
begin
printer.Title:='图片打印';
try
printer.begindoc;
printer.canvas.StretchDraw(rect,image1.Picture.Bitmap);
application.ProcessMessages;
printer.enddoc;
except
printer.Abort;
raise;
end;
end;
except
showmessage('没有打印机,请选择打印机!');
end;
end;