P
ppp
Unregistered / Unconfirmed
GUEST, unregistred user!
做了一个JPG图象打印程序,要求当JPG图象大小超出A4纸时缩小打印到A4纸上,
我用Printer.Canvas.StretchDraw来将图象缩小到合适的范围,打印出来的大
小倒没问题,但是质量很差,图象模糊不清,很粗糙;而用photoshop打印同一张图片,
打印出来的效果却是非常细腻,请问各位有什么好的打印方法能提高打印质量.
下面是我得打印程序
procedure TForm1.GetDeviceSettings;
begin
// FdeviceName :=Printer.Printers[Printer. PrinterIndex];
FpageHeightPixel := Printer.PageHeight;
FpageWidthPixel := Printer.PageWidth;
// Forientation:=Printer.Orientation;
FPixelsPerInchX:= GetDeviceCaps(Printer.Handle,LOGPIXELSX);
FPixelsPerInchY:= GetDeviceCaps (Printer.Handle,Logpixelsy);
FPixelsPerMMX:=INCHES_PER_MILIMETER*FPixelsPerInchX;
FPixelsPerMMY:=INCHES_PER_MILIMETER*FPixelsPerInchY;
// FpageHeightMM:=round(FpageHeightPixel/FPixelsPerMMY);
// FpageWidthMM:=round(FPageWidthPixel/FPixelsPerMMX);
RatioX:=FPixelsPerInchX/Screen.PixelsPerInch;
RatioY:=FPixelsPerInchY/Screen.PixelsPerInch;
offSetX:=GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX)/FPixelsPerMMX;
offSetY:=GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY)/FPixelsPerMMY;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
ImgWidth,ImgHeight:integer;
PrtLeft,PrtHeight,PrtWidth:integer;
begin
if Image1.Picture.Graphic=nil then
begin
showmessage('您没有选择要打印的资料');
exit;
end;
ComboBox2.Clear;
ComboBox2.Items.Assign(Printer.Printers);
if ComboBox2.Items.CommaText='' then
begin
Messagedlg('你需要安装打印机才能打印!',mtError,[mbOk],0);
exit;
end;
try
GetDeviceSettings;
Printer.Title:='资料';
Printer.begin
Doc;
ImgWidth:=Image2.Picture.Width;
ImgHeight:=Image2.Picture.Height;
if (ImgWidth*RatioX>FpageWidthPixel)and(ImgHeight*RatioY>FpageHeightPixel) then
begin
if ImgWidth/FpageWidthPixel>ImgHeight/FpageHeightPixel then
begin
PrtLeft:=0;
prtWidth:=FpageWidthPixel;
PrtHeight:=round(FpageWidthPixel*ImgHeight/ImgWidth);
end
else
begin
PrtHeight:=FpageHeightPixel;
prtWidth:=round(FpageHeightPixel*ImgWidth/ImgHeight);
prtLeft:=(FpageWidthPixel-prtWidth)div 2;
end;
end
else
if(ImgWidth*RatioX>FpageWidthPixel)and(ImgHeight*RatioY<=FpageHeightPixel) then
begin
PrtLeft:=0;
prtWidth:=FpageWidthPixel;
PrtHeight:=round(FpageWidthPixel*ImgHeight/ImgWidth);
end
else
if(ImgWidth*RatioX<=FpageWidthPixel)and(ImgHeight*RatioY>FpageHeightPixel) then
begin
PrtHeight:=FpageHeightPixel;
prtWidth:=round(FpageHeightPixel*ImgWidth/ImgHeight);
prtLeft:=(FpageWidthPixel-prtWidth)div 2;
end
else
if(ImgWidth*RatioX<=FpageWidthPixel)and(ImgHeight*RatioY<=FpageHeightPixel) then
begin
PrtWidth:=Round(ImgWidth*RatioX);
PrtHeight:=Round(ImgHeight*RatioY);
prtLeft:=(FpageWidthPixel-prtWidth)div 2;
end;
Printer.Canvas.StretchDraw(Rect(PrtLeft,0,PrtWidth+PrtLeft,PrtHeight),Image1.Picture.Graphic);
Printer.EndDoc;
Showmessage('打印完毕');
finally
end;
end;
我用Printer.Canvas.StretchDraw来将图象缩小到合适的范围,打印出来的大
小倒没问题,但是质量很差,图象模糊不清,很粗糙;而用photoshop打印同一张图片,
打印出来的效果却是非常细腻,请问各位有什么好的打印方法能提高打印质量.
下面是我得打印程序
procedure TForm1.GetDeviceSettings;
begin
// FdeviceName :=Printer.Printers[Printer. PrinterIndex];
FpageHeightPixel := Printer.PageHeight;
FpageWidthPixel := Printer.PageWidth;
// Forientation:=Printer.Orientation;
FPixelsPerInchX:= GetDeviceCaps(Printer.Handle,LOGPIXELSX);
FPixelsPerInchY:= GetDeviceCaps (Printer.Handle,Logpixelsy);
FPixelsPerMMX:=INCHES_PER_MILIMETER*FPixelsPerInchX;
FPixelsPerMMY:=INCHES_PER_MILIMETER*FPixelsPerInchY;
// FpageHeightMM:=round(FpageHeightPixel/FPixelsPerMMY);
// FpageWidthMM:=round(FPageWidthPixel/FPixelsPerMMX);
RatioX:=FPixelsPerInchX/Screen.PixelsPerInch;
RatioY:=FPixelsPerInchY/Screen.PixelsPerInch;
offSetX:=GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX)/FPixelsPerMMX;
offSetY:=GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY)/FPixelsPerMMY;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
ImgWidth,ImgHeight:integer;
PrtLeft,PrtHeight,PrtWidth:integer;
begin
if Image1.Picture.Graphic=nil then
begin
showmessage('您没有选择要打印的资料');
exit;
end;
ComboBox2.Clear;
ComboBox2.Items.Assign(Printer.Printers);
if ComboBox2.Items.CommaText='' then
begin
Messagedlg('你需要安装打印机才能打印!',mtError,[mbOk],0);
exit;
end;
try
GetDeviceSettings;
Printer.Title:='资料';
Printer.begin
Doc;
ImgWidth:=Image2.Picture.Width;
ImgHeight:=Image2.Picture.Height;
if (ImgWidth*RatioX>FpageWidthPixel)and(ImgHeight*RatioY>FpageHeightPixel) then
begin
if ImgWidth/FpageWidthPixel>ImgHeight/FpageHeightPixel then
begin
PrtLeft:=0;
prtWidth:=FpageWidthPixel;
PrtHeight:=round(FpageWidthPixel*ImgHeight/ImgWidth);
end
else
begin
PrtHeight:=FpageHeightPixel;
prtWidth:=round(FpageHeightPixel*ImgWidth/ImgHeight);
prtLeft:=(FpageWidthPixel-prtWidth)div 2;
end;
end
else
if(ImgWidth*RatioX>FpageWidthPixel)and(ImgHeight*RatioY<=FpageHeightPixel) then
begin
PrtLeft:=0;
prtWidth:=FpageWidthPixel;
PrtHeight:=round(FpageWidthPixel*ImgHeight/ImgWidth);
end
else
if(ImgWidth*RatioX<=FpageWidthPixel)and(ImgHeight*RatioY>FpageHeightPixel) then
begin
PrtHeight:=FpageHeightPixel;
prtWidth:=round(FpageHeightPixel*ImgWidth/ImgHeight);
prtLeft:=(FpageWidthPixel-prtWidth)div 2;
end
else
if(ImgWidth*RatioX<=FpageWidthPixel)and(ImgHeight*RatioY<=FpageHeightPixel) then
begin
PrtWidth:=Round(ImgWidth*RatioX);
PrtHeight:=Round(ImgHeight*RatioY);
prtLeft:=(FpageWidthPixel-prtWidth)div 2;
end;
Printer.Canvas.StretchDraw(Rect(PrtLeft,0,PrtWidth+PrtLeft,PrtHeight),Image1.Picture.Graphic);
Printer.EndDoc;
Showmessage('打印完毕');
finally
end;
end;