Moritz,
You can send the bitmap to any canvas using this which work in both D1
and D2 (StretchDraw,
Draw, etc. are very erratic when sending stuff to a printer.). To call it
use something like:
DrawImage(Printer.Canvas, Rect(Left, Top, Right, Bottom), MyBitmap);
procedure MemFree(Ptr: Pointer; Size: Longint);
begin
if Size < 65535 then
FreeMem(Ptr, Size)
else
GlobalFreePtr(Ptr);
end;
{Prints BitMap }
procedure DrawImage(Canvas: TCanvas; DestRect: TRect; ABitmap: TBitmap);
var
Header, Bits: Pointer;
HeaderSize: Integer;
{$IfDef Win32} {Checks if using Delphi 2.0}
BitsSize : Integer;
{$Else}
BitsSize : LongInt;
{$EndIf}
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.Left, DestRect.Bottom - DestRect.Top,
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;
Another neat feature (at least we thought so when we found out) of this
code is that if
you transpose the left-right and/or top-bottom coords for the Rect you can
flip the
bitmap horizontally and/or vertically.
Hope this helps!
--
Rod Geraghty (:>)
GERA-Tech
Ottawa, Canada
gera...@ibm.net
Moritz F. Koch <Moritz_K...@public.uni-hamburg.de> wrote in article
<5e5jv2$...@rzsun02.rrz.uni-hamburg.de>...
Quote
> Hi!
> I still have problems with printing via TPrinter.Canvas. When I draw a
> predefined Bitmap, e.g., on the Printer.Canvas in between BeginDoc and
> EndDoc the output willl not come out right. On my HP 520 the white
> background will be gray and not white (although I painted the
> background with Color=clWhite) and on a Sharp laser printer the output
> will be just a blank page!
> What did I do wrong? Does anybody have an answer or has encountered
> similar problems?
> Please help me!
> Moritz