StretchDraw an image to a printer canvas

Stretch drawing a graphic to a printer.canvas is very poor. Here is a better solution.

procedure DrawImage(Canvas: TCanvas; DestRect: TRect; ABitmap: TBitmap);

var

  Header, Bits: Pointer;

  HeaderSize: DWord;

  BitsSize: DWord;

begin

  GetDIBSizes(ABitmap.Handle, HeaderSize, BitsSize);

  GetMem(Header, HeaderSize);

  GetMem(Bits, 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);

  finally

    FreeMem(Header);



    FreeMem(Bits);

  end;

end;

 

Share this article!

Follow us!

Find more helpful articles: