今天必须解决,关于图形打印的问题,及求高手帮助!!! ( 积分: 100 )

  • 主题发起人 主题发起人 LanFairy
  • 开始时间 开始时间
L

LanFairy

Unregistered / Unconfirmed
GUEST, unregistred user!
var
bm: TBitmap;
ADevice, ADriver, APort: Array [0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode;
begin

//检测是否安装打印机
if NOT CheckIsSetupPrinter then
begin
InfoData(提示安装');
Exit;
end;

//判断打印机是否正在打印
if NOT Printer.Printing then
begin

//得到TDeviceMode结构,并进行设置
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
if DeviceHandle = 0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
end;

if DeviceHandle = 0 then
begin
InfoData('²»ÄܶÔTDeviceMode½á¹¹½øÐгõʼ»¯');
end else
begin
DevMode := GlobalLock(DeviceHandle);
end;

//设置打印结构
with DevMode^do
begin
dmFields := dmFields or DM_COLOR;
dmColor := DMCOLOR_COLOR;
end;

dmFields := dmFields or DM_ORIENTATION;
if SysParam.parPrint.ppOrient = 'ºáÏò´òÓ¡' then
dmOrientation := DMORIENT_LANDSCAPE
else
dmOrientation := DMORIENT_PORTRAIT;
//ÉèÖÃÖ½Õųߴç
dmFields := dmFields or DM_PAPERSIZE;
dmPapersize := 0;
//ÉèÖÃÖ½Õų¤¶È
dmFields := dmFields or DM_PAPERLENGTH;
dmPaperlength := 2970;
//ÉèÖÃÖ½ÕÅ¿í¶È
dmFields:=dmFields or DM_PAPERWIDTH;
dmPaperwidth := 2100;
//ÉèÖôòÓ¡±ÈÀý
dmFields := dmFields or DM_SCALE;
dmSCALE := 200;
//ÉèÖÃÖ½ÕÅÀàÐÍ
dmFields := dmFields or DM_PAPERSIZE;
dmPaperSize := DMPAPER_A4;
end;

//ÖØÐÂË¢ÐÂÒ»ÏÂͼÐÎ
menuReadData.Click;
//½øÐдòÓ¡
if PrintDialog.Execute then
begin
bm := TBitmap.Create;
try
Image1.Bitmap.SaveToFile('tmp.bmp');
bm.LoadFromFile('tmp.bmp');
bm.HandleType := bmDIB;
//Printer.begin
Doc;
PrintStrectBitmap(bm);
//Printer.Canvas.StretchDraw(bm.Canvas.ClipRect, bm);
//Printer.EndDoc;
finally
bm.Free;
DeleteFile('tmp.bmp');
end;
end;

//È¡ÏûËø¶¨
if NOT DeviceHandle = 0 then
GlobalUnLock(DeviceHandle);
end else
begin
InfoData('ϵͳÕýÔÚ´òÓ¡ÇëÉÔºó£¡');
end;
end;
 
var
bm: TBitmap;
ADevice, ADriver, APort: Array [0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode;
begin

//检测是否安装打印机
if NOT CheckIsSetupPrinter then
begin
InfoData(提示安装');
Exit;
end;

//判断打印机是否正在打印
if NOT Printer.Printing then
begin

//得到TDeviceMode结构,并进行设置
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
if DeviceHandle = 0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
end;

if DeviceHandle = 0 then
begin
InfoData('²»ÄܶÔTDeviceMode½á¹¹½øÐгõʼ»¯');
end else
begin
DevMode := GlobalLock(DeviceHandle);
end;

//设置打印结构
with DevMode^do
begin
dmFields := dmFields or DM_COLOR;
dmColor := DMCOLOR_COLOR;
end;

dmFields := dmFields or DM_ORIENTATION;
if SysParam.parPrint.ppOrient = 'ºáÏò´òÓ¡' then
dmOrientation := DMORIENT_LANDSCAPE
else
dmOrientation := DMORIENT_PORTRAIT;
//ÉèÖÃÖ½Õųߴç
dmFields := dmFields or DM_PAPERSIZE;
dmPapersize := 0;
//ÉèÖÃÖ½Õų¤¶È
dmFields := dmFields or DM_PAPERLENGTH;
dmPaperlength := 2970;
//ÉèÖÃÖ½ÕÅ¿í¶È
dmFields:=dmFields or DM_PAPERWIDTH;
dmPaperwidth := 2100;
//ÉèÖôòÓ¡±ÈÀý
dmFields := dmFields or DM_SCALE;
dmSCALE := 200;
//ÉèÖÃÖ½ÕÅÀàÐÍ
dmFields := dmFields or DM_PAPERSIZE;
dmPaperSize := DMPAPER_A4;
end;

//ÖØÐÂË¢ÐÂÒ»ÏÂͼÐÎ
menuReadData.Click;
//½øÐдòÓ¡
if PrintDialog.Execute then
begin
bm := TBitmap.Create;
try
Image1.Bitmap.SaveToFile('tmp.bmp');
bm.LoadFromFile('tmp.bmp');
bm.HandleType := bmDIB;
//Printer.begin
Doc;
PrintStrectBitmap(bm);
//Printer.Canvas.StretchDraw(bm.Canvas.ClipRect, bm);
//Printer.EndDoc;
finally
bm.Free;
DeleteFile('tmp.bmp');
end;
end;

//È¡ÏûËø¶¨
if NOT DeviceHandle = 0 then
GlobalUnLock(DeviceHandle);
end else
begin
InfoData('ϵͳÕýÔÚ´òÓ¡ÇëÉÔºó£¡');
end;
end;
 
打印时,打印方向可以设置
但是打印出来的图形总是非常小,而且只是在纸张的一角
 
我现在只要实现两个功能就可以,按纸张大小进行打印图片,并且能够设置打印方向
 
http://www.1110.net/down.asp?UserID=397254
 
设置好打印机的分办率。
 
打印机的DC和屏幕的DC有个比例关系,你需要自己调整
Printer.Canvas.ClipRect
好像是用这个,你自己去和你现在的Canvas比较,有个差距,然后根据比例映射过去
我以前曾经直接StretchDraw的方式,效果还行,注意引用Printers单元
 
多人接受答案了。
 
后退
顶部