晴
晴
Unregistered / Unconfirmed
GUEST, unregistred user!
在image.canvas中画的图像为什么打印不出来,而用loadfrom调用的土却打印得出来?
代码:
procedure TForm1.FormCreate(Sender: TObject);
begin
with image1do
begin
canvas.Rectangle(30,30,100,100);
canvas.LineTo(150,150);
//image1.Picture.LoadFromFile('/all_bmp/close.bmp');
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var
AspectRatio: Single;
OutputWidth, OutputHeight: Single;
begin
if not PrintDialog1.Execute then
Exit;
Printer.begin
Doc;
try
OutputWidth := Image1.Picture.Width;
OutputHeight := Image1.Picture.Height;
AspectRatio := OutputWidth / OutputHeight;
if OutputWidth > Printer.PageWidth then
begin
OutputWidth := Printer.PageWidth;
OutputHeight := OutputWidth / AspectRatio;
end;
if OutputHeight > Printer.PageHeight then
begin
OutputHeight := Printer.PageHeight;
OutputWidth := OutputHeight * AspectRatio;
end;
Printer.Canvas.StretchDraw(Rect(0,0,
Trunc(outputWidth), Trunc(OutputHeight)),
Image1.Picture.Graphic);
{BltTBitmapAsDib(Printer.Canvas.Handle,
0,
0,
Image1.Picture.Bitmap.Width,
Image1.Picture.Bitmap.Height,
Image1.Picture.Bitmap);
end;
}
finally
Printer.EndDoc;
end;
end;
代码:
procedure TForm1.FormCreate(Sender: TObject);
begin
with image1do
begin
canvas.Rectangle(30,30,100,100);
canvas.LineTo(150,150);
//image1.Picture.LoadFromFile('/all_bmp/close.bmp');
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var
AspectRatio: Single;
OutputWidth, OutputHeight: Single;
begin
if not PrintDialog1.Execute then
Exit;
Printer.begin
Doc;
try
OutputWidth := Image1.Picture.Width;
OutputHeight := Image1.Picture.Height;
AspectRatio := OutputWidth / OutputHeight;
if OutputWidth > Printer.PageWidth then
begin
OutputWidth := Printer.PageWidth;
OutputHeight := OutputWidth / AspectRatio;
end;
if OutputHeight > Printer.PageHeight then
begin
OutputHeight := Printer.PageHeight;
OutputWidth := OutputHeight * AspectRatio;
end;
Printer.Canvas.StretchDraw(Rect(0,0,
Trunc(outputWidth), Trunc(OutputHeight)),
Image1.Picture.Graphic);
{BltTBitmapAsDib(Printer.Canvas.Handle,
0,
0,
Image1.Picture.Bitmap.Width,
Image1.Picture.Bitmap.Height,
Image1.Picture.Bitmap);
end;
}
finally
Printer.EndDoc;
end;
end;