Board index » delphi » printing graphics...??

printing graphics...??

Hi all!

Is there somebody out there who has tried printing graphics according to the
method descrbied in the delphi manual on page 351/352? I tried this, but the
printer (laserjet 4Si) will only print blank pages. If I draw directly on the
printers canvas it works, but this is probably not the way to do it, because
then I have to write two dedicated printing routines.

Any info appreciated.

Regards,  Gerry.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Gerry van Dooren, e-mail: gvdoo...@estec.esa.nl
European Space Agency/ESTEC
PO Box 299, 2200 AG Noordwijk
The Netherlands
tel.: +31-71-565-4664
fax.: +31-71-565-4999

 

Re:printing graphics...??


In article <56s19r$...@bcalpha.estec.esa.nl>, Gerry van Dooren
<gvdoo...@vmprofs.estec.esa.nl> writes

Quote
>Hi all!

>Is there somebody out there who has tried printing graphics according to the
>method descrbied in the delphi manual on page 351/352? I tried this, but the
>printer (laserjet 4Si) will only print blank pages. If I draw directly on the
>printers canvas it works, but this is probably not the way to do it, because
>then I have to write two dedicated printing routines.

I have had the same problem trying to print a bitmap to a Windows GDI
printer using both Draw and StretchDraw. The StretchDraw method
illustratd in the Delphi Developer's Guide (p.183) also results in the
same blank page.

Since I want to show these bitmaps in reports, I find that dropping a
TImage onto a QuickReport form and then printing that does the trick,
using Assign to copy the bitmap across.

If anyone has a bullet-proof routine for printing bitmaps from a Delphi
application - please post it here.
--
Barney Tyrwhitt-Drake

Re:printing graphics...??


In article <56s19r$...@bcalpha.estec.esa.nl>, Gerry van Dooren
<gvdoo...@vmprofs.estec.esa.nl> writes

Quote
>Hi all!

>Is there somebody out there who has tried printing graphics according to the
>method descrbied in the delphi manual on page 351/352? I tried this, but the
>printer (laserjet 4Si) will only print blank pages. If I draw directly on the
>printers canvas it works, but this is probably not the way to do it, because
>then I have to write two dedicated printing routines.

>Any info appreciated.

>Regards,  Gerry.

I would be glad to hear from anyone who has printed graphics from T
PASCAL Ver 7*  !

Cheers, Jim

Jim Barr        Machine Conversation
                http://www.wandana.demon.co.uk/
                Best is the enemy of good enough
                Leaves rustle, blades turn,   water moves

Re:printing graphics...??


Gerry van Dooren  wrote

Quote
> Is there somebody out there who has tried printing graphics according to
the
> method descrbied in the delphi manual on page 351/352? I tried this, but
the
> printer (laserjet 4Si) will only print blank pages. If I draw directly on
the
> printers canvas it works, but this is probably not the way to do it,
because
> then I have to write two dedicated printing routines.

> Any info appreciated.

> Regards,  Gerry.

There is a  (long) tecnical information  that can be downloaded at
http://www.borland.com/techsupport/delphi/techdocs/index.html
Is the TI3155- A Better way to print a form.
There is a lot of code to explain how convert the image on the canvas (or a
bitmap) to a DIBitmap and then send the bitmap to the printer with the API
functions.

--
Furio Gerace
dpt. of Chemistry Univ. of Rome
ger...@axrma.uniroma1.it

Re:printing graphics...??


On 19 Nov 1996 10:14:19 GMT, gvdoo...@vmprofs.estec.esa.nl (Gerry van

Quote
Dooren) wrote:
>Hi all!

>Is there somebody out there who has tried printing graphics according to the
>method descrbied in the delphi manual on page 351/352? I tried this, but the
>printer (laserjet 4Si) will only print blank pages. If I draw directly on the
>printers canvas it works, but this is probably not the way to do it, because
>then I have to write two dedicated printing routines.

>Any info appreciated.

>Regards,  Gerry.

>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>Gerry van Dooren, e-mail: gvdoo...@estec.esa.nl
>European Space Agency/ESTEC
>PO Box 299, 2200 AG Noordwijk
>The Netherlands
>tel.: +31-71-565-4664
>fax.: +31-71-565-4999

This is from the Delphi MANUALS.TXT file that comes with 1.x:
Using StretchDIBits instead of Draw for bitmap printing
-------------------------------------------------------
Bitmap printing - When printing a bitmap, make sure to use the
Windows API routine StretchDIBits. For example, here's a function
that prints an arbitrary TBitmap at the specified X,Y location:

  procedure PrintBitmap(Bitmap: TBitmap; X, Y: Integer);
  var
    Info: PBitmapInfo;
    InfoSize: Integer;
    Image: Pointer;
    ImageSize: Longint;
  begin
    with Bitmap do
    begin
      GetDIBSizes(Handle, InfoSize, ImageSize);
      Info := MemAlloc(InfoSize);
      try
        Image := MemAlloc(ImageSize);
        try
          GetDIB(Handle, Palette, Info^, Image^);
          with Info^.bmiHeader do
            StretchDIBits(Printer.Canvas.Handle, X, Y, Width,
              Height, 0, 0, biWidth, biHeight, Image, Info^,
              DIB_RGB_COLORS, SRCCOPY);
        finally
          FreeMem(Image, ImageSize);
        end;
      finally
        FreeMem(Info, InfoSize);
      end;
    end;
  end;
-----------------------------------------------------------------

Re:printing graphics...??


Quote
Jim Barr wrote:
> I would be glad to hear from anyone who has printed graphics from T
> PASCAL Ver 7*  !

There are tech docs from Borland on this. Nums 432 & 433. One for
Epson and another for LaserJet. I tried it a few days ago. Didn't
fool with it enough to tweek output, but it works.

I necessary I can e-mail the docs to you.

Jim
--
Communications Analysis Prediction Wizard
http://www.wtrt.net/~ku5s/
CAPMan HF Propagation Prediction & System Analysis Software
http://ourworld.compuserve.com/homepages/KU5S

Re:printing graphics...??


Quote
> >Is there somebody out there who has tried printing graphics according to the
> >method descrbied in the delphi manual on page 351/352? I tried this, but the
> >printer (laserjet 4Si) will only print blank pages. If I draw directly
on the
> >printers canvas it works, but this is probably not the way to do it, because
> >then I have to write two dedicated printing routines.

> I have had the same problem trying to print a bitmap to a Windows GDI
> printer using both Draw and StretchDraw. The StretchDraw method
> illustratd in the Delphi Developer's Guide (p.183) also results in the
> same blank page.

> Since I want to show these bitmaps in reports, I find that dropping a
> TImage onto a QuickReport form and then printing that does the trick,
> using Assign to copy the bitmap across.

> If anyone has a bullet-proof routine for printing bitmaps from a Delphi
> application - please post it here.

The following is thanks to Danny Thorpe
 author of "Delphi Component Design" 1996 Addison Wesley
 ISBN 0-201-46136-6

The following text is from the Delphi readme file MANUALS.TXT:

Using StretchDIBits instead of Draw for bitmap printing
-------------------------------------------------------
Bitmap printing - When printing a bitmap, make sure to use the
Windows API routine StretchDIBits. For example, here's a function
that prints an arbitrary TBitmap at the specified X,Y location:

  procedure PrintBitmap(Bitmap: TBitmap; X, Y: Integer);
  var
    Info: PBitmapInfo;
    InfoSize: Integer;
    Image: Pointer;
    ImageSize: Longint;
  begin
    with Bitmap do
    begin
      GetDIBSizes(Handle, InfoSize, ImageSize);
      Info := MemAlloc(InfoSize);
      try
        Image := MemAlloc(ImageSize);
        try
          GetDIB(Handle, Palette, Info^, Image^);
          with Info^.bmiHeader do
            StretchDIBits(Printer.Canvas.Handle, X, Y, Width,
              Height, 0, 0, biWidth, biHeight, Image, Info^,
              DIB_RGB_COLORS, SRCCOPY);
        finally
          FreeMem(Image, ImageSize);
        end;
      finally
        FreeMem(Info, InfoSize);
      end;
    end;
  end;

Two gotchas with this code, that another programmer in my company ran
into: 1) he couldnt get it to work with Graphichs.TBitmaps that had the
monochrome prop set to true and 2) MemAlloc can accept a LongInt, but
FreeMem only accepts a (word or integer; I cant remember which). Try
using GlobalAlloc/Free instead.

Ed Eichman
Cambrils, Spain

Other Threads