有关打印位图的问题!!(50分)

  • 主题发起人 主题发起人 小橄榄
  • 开始时间 开始时间

小橄榄

Unregistered / Unconfirmed
GUEST, unregistred user!
现需要把位图文件(.bmp)输出到打印机上的API函数,急用,请大家帮帮忙。<br>最好有个例子。
 
procedure TMainForm.N11Click(Sender: TObject);<br>var<br>&nbsp; ScaleX,ScaleY :Integer;<br>&nbsp; R :TRect;<br>begin<br>&nbsp; if Printer.Printers.Count=0 then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('请首先安装打印机');<br>&nbsp; &nbsp; Exit; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//跳出N11Click<br>&nbsp; end;<br>&nbsp; if not MainPrintDialog.Execute then Exit<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; with Printer do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; BeginDoc;<br>&nbsp; &nbsp; &nbsp; ScaleX :=GetDeviceCaps(Handle,LogPixelsX) div PixelsPerInch;<br>&nbsp; &nbsp; &nbsp; ScaleY :=GetDeviceCaps(Handle,LogPixelsY) div PixelsPerInch;<br>&nbsp; &nbsp; &nbsp; R :=Rect(0,0,MDIChildForm.MainImage.Width*ScaleX,MDIChildForm.MainImage.Height*ScaleY);<br>&nbsp; &nbsp; &nbsp; Canvas.StretchDraw(R,MDIChildForm.MainImage.Picture.Graphic);<br>&nbsp; &nbsp; &nbsp; EndDoc;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br>记得添加Printers单元。
 
TO卷起千堆雪tyn:因为程序中的关系,只能用Windows的API函数,不能用Delphi封装过的。<br>
 
如果想原样打印,请使用下面的API函数<br>BOOL BitBlt(<br><br>&nbsp; &nbsp; HDC hdcDest, // 目标设备DC句柄,如果打印则为打印机DC<br>&nbsp; &nbsp; int nXDest, // 目标矩形的左上角横坐标<br>&nbsp; &nbsp; int nYDest, // 目标矩形的左上角纵坐标<br>&nbsp; &nbsp; int nWidth, // 目标矩形的宽度<br>&nbsp; &nbsp; int nHeight, // 目标矩形的高度<br>&nbsp; &nbsp; HDC hdcSrc, // 源设备DC句柄<br>&nbsp; &nbsp; int nXSrc, // 原矩形的左上角横坐标<br>&nbsp; &nbsp; int nYSrc, // 源矩形的左上角纵坐标<br>&nbsp; &nbsp; DWORD dwRop // 光栅操作<br>&nbsp; &nbsp;);<br>如果想缩放图像使用下面的函数,参数含义基本同上 <br>BOOL StretchBlt(<br><br>&nbsp; &nbsp; HDC hdcDest, // handle of destination device context <br>&nbsp; &nbsp; int nXOriginDest, // x-coordinate of upper-left corner of dest. rect. <br>&nbsp; &nbsp; int nYOriginDest, // y-coordinate of upper-left corner of dest. rect. <br>&nbsp; &nbsp; int nWidthDest, // width of destination rectangle <br>&nbsp; &nbsp; int nHeightDest, // height of destination rectangle <br>&nbsp; &nbsp; HDC hdcSrc, // handle of source device context <br>&nbsp; &nbsp; int nXOriginSrc, // x-coordinate of upper-left corner of source rectangle <br>&nbsp; &nbsp; int nYOriginSrc, // y-coordinate of upper-left corner of source rectangle <br>&nbsp; &nbsp; int nWidthSrc, // width of source rectangle <br>&nbsp; &nbsp; int nHeightSrc, // height of source rectangle <br>&nbsp; &nbsp; DWORD dwRop // raster operation code <br>&nbsp; &nbsp;); <br><br>
 
接受答案了.
 
后退
顶部