Board index » cppbuilder » Printing a TBitmap

Printing a TBitmap

Hi all

I'm having real problems printing a TBitmap under BCB4. I had it working under BCB1 & 3, but NOTHING prints under BCB4.

My code is:

        //BCB 1  & 3
        //Graphics::TBitmap *Bitmap;
        //Bitmap = new Graphics::TBitmap();
        //TRect rect;
        //rect.Top = 0;
        //rect.Left = 0;
        //rect.Right = pPrinter->PageWidth;
        //rect.Bottom = pPrinter->PageHeight;
        //end BCB1 & 3 code

        //pPrinter is a previously defined TPrinter object

        pPrinter->BeginDoc();
        pPrinter->Canvas->CopyMode = cmSrcCopy;

        //debug code - works for all versions of BCB
        pPrinter->Canvas->TextOut(0, 0, "Test print");
        //end debug code

        //BCB4 code
        //PreviewImage is a TImage control.

        Bitmap = PreviewImage->Picture->Bitmap;

        //BCB 1 & 3 code

        //Bitmap->LoadFromFile("C:\\temp.bmp");
        //pPrinter->Canvas->StretchDraw(rect,PreviewImage->Picture->Bitmap);
        //end BCB 1 & 3 code

        //BCB 4 code - straight from the help file example, bar variable name changes

        pPrinter->Canvas->Draw((pPrinter->PageWidth - Bitmap->Width)/2,
                      (pPrinter->PageHeight - Bitmap->Height)/2,
                      Bitmap);

        pPrinter->EndDoc();

        //BCB 1 & 3 code
        //delete Bitmap;

Under BCB 1 & 3, the only way I could get a TBitmap to print was by using the LoadFromFile method. Under BCB 4, absolutley nothing (apart
from the test text) prints, whatever method I use.

Does anyone know how to do this?

--
Andy Bell

 

Re:Printing a TBitmap


Hi Andy,

Quote
> I'm having real problems printing a TBitmap under BCB4 ...
>         pPrinter->Canvas->Draw((pPrinter->PageWidth - Bitmap->Width)/2,
>                       (pPrinter->PageHeight - Bitmap->Height)/2,
>                       Bitmap);

You should be using the StretchDIBits() API function instead of the
TCanvas::Draw() method.  The "DI" in StretchDIBits() stands for "Device
Independent".  Since you're drawing on the device context of a device other than
the screen, namely the printer, it's more reliable to use device independent
means.  Have a look at this CAQ for more info...

http://bcbcaq.freeservers.com/print_graphics.html

Good luck!

--------------------------------------
Damon Chandler

http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>
52064929

Re:Printing a TBitmap


Thanks. I'll give it a go!

In article <384586AE.E3F09...@cornell.edu>, Damon Chandler
<dm...@cornell.edu> writes

Quote
>Hi Andy,
>> I'm having real problems printing a TBitmap under BCB4 ...
>>         pPrinter->Canvas->Draw((pPrinter->PageWidth - Bitmap->Width)/2,
>>                       (pPrinter->PageHeight - Bitmap->Height)/2,
>>                       Bitmap);

>You should be using the StretchDIBits() API function instead of the
>TCanvas::Draw() method.  The "DI" in StretchDIBits() stands for "Device
>Independent".  Since you're drawing on the device context of a device other than
>the screen, namely the printer, it's more reliable to use device independent
>means.  Have a look at this CAQ for more info...

>http://bcbcaq.freeservers.com/print_graphics.html

>Good luck!

>--------------------------------------
>Damon Chandler

>http://bcbcaq.freeservers.com
>Answers to <Commonly Asked Questions>
>52064929

--
Andy Bell

Other Threads