Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to print bitmaps safely

134 views
Skip to first unread message

Mark A. Malakanov

unread,
Nov 18, 1997, 3:00:00 AM11/18/97
to

Now I print bitmaps using Delphi Printer object into Canvas.
I simply Draw or Copy bitmaps to printer canvas.
On some printers it works good, but on other it is bad result.
Only lines, texts or shapes is printed - no bitmaps. By example it is
Epson820 and Epson200 doesn't print bitmaps.
But it this time other application prints the bitmaps good on this printer.
Why?
QuickReport prints bitmaps too. (I dont use it - i need russian preview
interface)

I'v tried many bitmap formats, I'v checked out printer possibility of
StretchBlt and StretchDIBits operations. This is OK. But I can not get good
result - bitmaps is not printed. :((((
I used all WinAPI functions : StretchBlt and StretchDIBits ,
StretchDIBitsToDevice, etc. - NO BITMAPS - only vector graphics!

What must I do?
Heeeeeeeeeeeeeeeeeeeeellllllllllllllllllpppppppppppppp!!!!!!!!!!!!!!!!

--
Regards,
Mark
!!!ERASE ".NO_SPAM"!!! ma...@av.krasnoyarsk.su.NO_SPAM


Rodney E Geraghty

unread,
Nov 19, 1997, 3:00:00 AM11/19/97
to

Mark,
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
ger...@ibm.net

Mark A. Malakanov <ma...@av.krasnoyarsk.su> wrote in article
<EJtqF...@sable.krasnoyarsk.su>...

0 new messages