Einzelnen Beitrag anzeigen

Muetze1
(Gast)

n/a Beiträge
 

Re: Probleme bei Ausdruck von Bitmaps

  Alt 20. Apr 2004, 20:30
Moin!

StretchDraw, BitBlt, etc werden nicht von allen Druckertreibern unterstützt - das ist das Problem. Dabei tritt es oft auch schon bei dem gleichen Drucker und unterschiedlichen Windows Versionen auf.

Folgender Weg macht das immer:
Code:
  // Based on posting to borland.public.delphi.winapi by Rodney E Geraghty,
  // 8/8/97. Used to print bitmap on any Windows printer.
  PROCEDURE PrintBitmap(Canvas: TCanvas; DestRect: TRect; Bitmap: TBitmap);
    VAR
      BitmapHeader: pBitmapInfo;
      BitmapImage : POINTER;
      HeaderSize : DWORD;   // Use DWORD for compatibility with D3-D5
      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};
Wie der Code angibt, aus der borland delphi newsgroup.

MfG
Muetze1
  Mit Zitat antworten Zitat