Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Drucken mit Procedure PrintBitmap an Stelle von StretchDraw (https://www.delphipraxis.net/152848-drucken-mit-procedure-printbitmap-stelle-von-stretchdraw.html)

diver03 9. Jul 2010 10:11

Drucken mit Procedure PrintBitmap an Stelle von StretchDraw
 
Hallo

nach dem ich nach einem Druckerwechsel Probleme hatte, dass Bitmaps
mit stretchdraw teilweise nicht mehr gedruckt wurde habe ich das
Drucken der Bitmaps auf die Procedure PrintBitmap (habe ich hier
im Forum gefunden) umgestellt.

Delphi-Quellcode:
  // 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};
Das funktioniert auch sehr gut mit Bitmaps.
Mit jpg bekomme ich das aber nicht zum Laufen, da die Procedur ein TBitmap
erwartet, aber mit einem TGraphic nichts anfangen kann.

Kann mir jemand sagen, wie eine Procedure aussehen muss, die auch TGraphic verarbeiten kann?

Gruß
Jens

timog 21. Jul 2010 14:59

AW: Drucken mit Procedure PrintBitmap an Stelle von StretchDraw
 
Hallo Jens,

ich habe auch gerade die von Dir ausgebuddelte procedure entdeckt. Den Aufruf der Prozedur mit einem JPG habe ich so gelöst (beispielhaft):
Delphi-Quellcode:
var
  jpg: TJPEGImage;
  bmp: TBitmap;
  r: TRect;
begin
  if FileExists('logo.jpg') then begin
    jpg:=nil;
    bmp:=nil;
    try
      jpg := TJPEGImage.Create;
      bmp := TBitmap.Create;
      jpg.LoadFromFile('logo.jpg');
      bmp.Assign(jpg);
      // Hier wird r berechnet, etc.
      PrintBitmap(Canvas, r, bmp);
    finally
      jpg.Free;
      bmp.Free;
    end;
  end;
Try/Finally-Block nach Olaf's Blog

Viele Grüße

Timo

hoika 21. Jul 2010 16:25

AW: Drucken mit Procedure PrintBitmap an Stelle von StretchDraw
 
Hallo,

schäm,

der Monien könnte Recht haben


Heiko

Monien 12. Aug 2010 15:31

AW: Drucken mit Procedure PrintBitmap an Stelle von StretchDraw
 
... und wenn der Monien mal nicht Recht hat, dann tritt automatisch §1 in Kraft ;-)


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:16 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz