如何将一个位图对象打印出来?要求可以伸缩,调整起始位置,清高手赐教一段代码.

解决方案 »

  1.   

    uses
      Printers;
    procedure PrintGraphic(g: TGraphic);
    begin
      Printer.BeginDoc;
      Printer.Canvas.Draw(0,0,g);
      Printer.EndDoc;
    end;
      

  2.   

    [转帖]: [email protected] (Alexander Wernhart)On Tue, 4 Feb 1997 20:54:43 -0300, Ruy Ponce de Leon Junior
    <[email protected]> wrote:
    I'm writing a program that prints a bitmap to the printer
    via TPrinter object. The problem occurs when I "stretch"
    the bitmap to fit the adequate area on paper. Due to the
    stretching (bitblts to Printer's DC), dotted patterns appear
    on the  bitmap regions, making them almost gray.
    This is an obvius undesired effect. Does anybody knows some 
    approach to help me?
     
    Try this:
    --------------------------------------------------------------------------------procedure DrawImage(Canvas: TCanvas; DestRect: TRect; ABitmap:
    TBitmap);
    var
      Header, Bits: Pointer;
      HeaderSize: Integer;
      BitsSize: Longint;
    begin
      GetDIBSizes(ABitmap.Handle, HeaderSize, BitsSize);
      Header := MemAlloc(HeaderSize);
      Bits := MemAlloc(BitsSize);
      try
        GetDIB(ABitmap.Handle, ABitmap.Palette, Header^, Bits^);
        StretchDIBits(Canvas.Handle, DestRect.Left, DestRect.Top,
            DestRect.Right, DestRect.Bottom,
            0, 0, ABitmap.Width, ABitmap.Height, Bits,TBitmapInfo(Header^),
            DIB_RGB_COLORS, SRCCOPY);
        { you might want to try DIB_PAL_COLORS instead, but this is well
          beyond the scope of my knowledge. }
      finally
        MemFree(Header, HeaderSize);
        MemFree(Bits, BitsSize);
      end;
    end;{ Print a Bitmap using the whole Printerpage }
    procedure PrintBitmap(ABitmap: TBitmap);
    var
      relheight, relwidth: integer;
    begin
      screen.cursor := crHourglass;
      Printer.BeginDoc;
      if ((ABitmap.width / ABitmap.height) > (printer.pagewidth /printer.pageheight)) then
      begin
        { Stretch Bitmap to width of Printerpage }
        relwidth := printer.pagewidth;
        relheight := MulDiv(ABitmap.height, printer.pagewidth,ABitmap.width);
      end else
      begin
        { Stretch Bitmap to height of Printerpage }
        relwidth := MulDiv(ABitmap.width, printer.pageheight, ABitmap.height);
        relheight := printer.pageheight;
      end;
      DrawImage(Printer.Canvas, Rect(0, 0, relWidth, relHeight), ABitmap);
      Printer.EndDoc;
      screen.cursor := crDefault;
    end;--------------------------------------------------------------------------------
    
      

  3.   

    Canvas.StretchDraw 实现缩放,然后打印。
      

  4.   

    谢谢赐教,我试了以下代码,打印可以,但是打出来的图像和实际显示的不一样大,小小的一块,怎么样才能改变打印的大小和实际显示的差不多呢?谢谢  Printer.BeginDoc;
      //Printer.Canvas.Draw(0,0,treChart.Image);
      Printer.Canvas.StretchDraw(Canvas.ClipRect,treChart.Image);
      Printer.EndDoc;