procedure TSDIAppForm.Button2Click(Sender: TObject);
var
pxprint,pyprint:Integer;
rect:Trect;
jpg: TJPEGImage;
begin
inherited;
try
//获得打印机的分辨率,就是每英寸多少个像素
pxprint := getdevicecaps(printer.Handle,logpixelsx);
pyprint := getdevicecaps(printer.Handle,logpixelsy);
//设置图片的打印区域,现在用的是A4:21cm*29.5cm
with rect do
begin
left := 0;
top := 0;
right := trunc(21*0.3937008*pxprint);
bottom:= trunc(29.5*0.3937008*pyprint);
end;
//向打印机输出图片
jpg := TJPEGImage.Create;
jpg.LoadFromFile('.\jpgtemp\frompro-000.jpg');
with jpg {image1.Picture.Bitmap} do
begin
printer.Title:= '图片打印 ';
try
printer.begindoc;
printer.canvas.StretchDraw(rect,jpg);
application.ProcessMessages;
printer.enddoc;
except
printer.Abort;
raise;
end;
end;
except
showmessage( '没有打印机,请选择打印机! ');
end;
jpg.free;
end;
开始时别忘了“uses jpeg;”