Leigh,
There are known problems when using Draw and StretchDraw to send things
to the printer. On some printers nothing is printed or intermittently
nothing is printed. Instead try the following code which may also fix your
problem (it works in D1 and D2. Needs modification to work in D3 which is
shown after the D1/D2 version):
****** Delphi 1 and Delphi 2 version ******
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);
finally
MemFree(Header, HeaderSize);
MemFree(Bits, BitsSize);
end;
end;
To call it use something like:
DrawImage(Printer.Canvas, Rect(Left, Top, Right, Bottom), MyBitmap);
This is similar to the code which is provided in the Manuals.txt file
(it's at the end of the txt file) that is installed in the Delphi directory
of D1.
****** Delphi 3 version (I haven't tested this but have been told it works)
******
procedure DrawImage(Canvas: TCanvas; DestRect: TRect; ABitmap: TBitmap);
var
Header, Bits: Pointer;
HeaderSize, BitsSize: Integer;
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.Left, DestRect.Bottom - DestRect.Top,
0, 0, ABitmap.Width, ABitmap.Height, Bits, TBitmapInfo(Header^),
DIB_RGB_COLORS, SRCCOPY);
finally
FreeMem(Header, HeaderSize);
FreeMem(Bits, BitsSize);
end;
end;
To call it use something like:
DrawImage(Printer.Canvas, Rect(Left, Top, Right, Bottom), MyBitmap);
Of course in either case you will heve to scale the values of Rect(Left,
Top, Right, Bottom) according to the DPI setting of the printer.
Hope this helps!
--
Rodney E Geraghty
GERA-Tech
Ottawa, Canada
gera...@ibm.net
Leigh Harrison <le...@radioshop.co.nz> wrote in article
<01bcf85f$37d1a900$0100007f@workroom>...
Quote
> _________________________________________
> When I print a bitmap to the printer it's printed with a grid behind it.
> The grid scales with the bitmap if I use StretchDraw instead of Draw.
Even
> when i convert the bitmap to a DIB it's still there.
> I've tried SetBkColor, SetBkMode, altered the Brush and Pen styles,
colors
> and modes on the bitmap ... no joy. I've imported the bitmaps into Paint
> and used floodfill to ensure there's nothing untoward on the canvas -
they
> look just fine in preview in any case.
> Have you encountered this - and (very importantly!) do you know the cure?
> Regards ...
> _________________________________________
> ? Leigh Harrison
> ? tel +64 6 343 2671
> ? fax +64 6 343 2649
> ? mobile 025 933 913
> ? email le...@radiOshop.co.nz
> ? 3 Iris Place Wanganui New Zealand
> _________________________________________
> radiOshop