如何打印Image中的图象?(100分)

心雨

Unregistered / Unconfirmed
GUEST, unregistred user!
如何打印Image中的图象?
 
with Printer do
begin
BeginDoc;
Canvas.draw(0,0,image1.canvas);
EndDoc;
end;

好像是这样,我记不情了,你再看看帮助就ok了
 
procedure TForm1.Button1Click(Sender: TObject);

begin
with Printer do
begin
BeginDoc;
Canvas.TextRect(Rect(200,200,PageWidth-200,PageHeight-200),
200, 200, Memo1.Lines.Text);
EndDoc;
end;

end;
DELPHI帮助文件里面的例子!
 
var
myrect:trect;//定义打印输出矩形框的大小
begin
Printer.BeginDoc;
begin
//定义标题字体
printer.canvas.font.name:='宋体';
//定义标题字体大小
printer.canvas.font.size:=14;
//打印标题
printer.canvas.textout();//打印文字的位置和具体文字
Myimg:=tbitmap.Create;
Myimg.LoadFromFile('C:/Program Files/tmp.bmp');
Printer.Canvas.StretchDraw(myrect,Myimg);
finally
Printer.EndDoc;
end;
end;
 
一个老外写的例子,效果很好,呵呵
procedure PrintBitmap(Canvas: TCanvas; DestRect: TRect; Bitmap: TBitmap);
var
BitmapHeader: pBitmapInfo;
BitmapImage: POINTER;
HeaderSize: DWORD; // Use DWORD for D3-D5 compatibility
ImageSize: DWORD;
begin
GetDIBSizes(Bitmap.Handle, HeaderSize, ImageSize);
GetMem(BitmapHeader, HeaderSize);
GetMem(BitmapImage, ImageSize);
try
GetDIB(Bitmap.Handle, Bitmap.Palette, BitmapHeader^, BitmapImage^);
StretchDIBits(Canvas.Handle,
DestRect.Left, DestRect.Top, // Destination Origin
DestRect.Right - DestRect.Left, // Destination Width
DestRect.Bottom - DestRect.Top, // Destination Height
0, 0, // Source Origin
Bitmap.Width, Bitmap.Height, // Source Width & Height
BitmapImage,
TBitmapInfo(BitmapHeader^),
DIB_RGB_COLORS,
SRCCOPY)
finally
FreeMem(BitmapHeader);
FreeMem(BitmapImage)
end
end {PrintBitmap};
{-----------------------------------------------------------------------------
Procedure: CenterText
Author: huazai
Date: 15-ʮһÔÂ-2002
Arguments: »ñÈ¡Êä³ö×Ö·ûµÄºáÏòλÖÃ
Result: INTEGER
-----------------------------------------------------------------------------}

function CenterText(s: string): INTEGER;
begin
RESULT := (Printer.PageWidth - Printer.Canvas.TextWidth(s)) div 2
end {CenterText};

procedure PrintFooterTimeStamp(const LeftMargin: INTEGER);
var
s: string;
begin
//Footer
Printer.Canvas.Font.Name := 'Arial';
Printer.Canvas.Brush.Color := clWhite;
Printer.Canvas.Font.Height :=
MulDiv(GetDeviceCaps(Printer.Canvas.Handle, LOGPIXELSY), 8, 72);
s := FormatDateTime('m/d/yy h:nn', Now);
Printer.Canvas.TextOut(LeftMargin,
Printer.PageHeight - Printer.Canvas.TextHeight('X'),
s);
end {PrinterFooterTimeStamp};

procedure TMainForm.printClick(Sender: TObject);
var
iFromLeftMargin: INTEGER;
iPrintedImageWidth: INTEGER;
jDelta: INTEGER;
jFromTopOfPage: INTEGER;
jPrintedImageHeight: INTEGER;
s: string;
begin
if PrinterSetupDialog1.Execute then
begin
Screen.Cursor := crHourGlass;
try
Printer.BeginDoc;
// Header
Printer.Canvas.Font.Height :=
MulDiv(GetDeviceCaps(Printer.Canvas.Handle, LOGPIXELSY), 12, 72);
Printer.Canvas.Font.Name := 'Arial';
jDelta := Printer.Canvas.TextHeight('X');
jFromTopOfPage := 3 * jDelta;
s := 'Image Processer';
Printer.Canvas.TextOut(CenterText(s), jFromTopOfPage, s);
// 5th line from top
jFromTopOfPage := 5 * jDelta;
// Image position and size
// 12% left and right margin
iFromLeftMargin := MulDiv(Printer.PageWidth, 12, 100); // 12%
// Set printed bitmap with to be 76% of paper width
iPrintedImageWidth := MulDiv(Printer.PageWidth, 76, 100); // 76%
// Set printed bitmap height to maintain aspect ratio
jPrintedImageHeight := childform.Image1.Picture.Bitmap.Height *
iPrintedImageWidth div
childform.Image1.Picture.Bitmap.Width;
// maintain aspect ratio of bitmap
// Print Image
PrintBitmap(Printer.Canvas,
Rect(iFromLeftMargin, jFromTopOfPage,
iFromLeftMargin + iPrintedImageWidth,
jFromTopOfPage + jPrintedImageHeight),
childform.Image1.Picture.Bitmap);
ShowMessage('Bitmap printed');
PrintFooterTimeStamp(iFromLeftMargin);
Printer.EndDoc
finally
Screen.Cursor := crDefault
end

end

end;
 
多人接受答案了。
 
顶部