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

TPrinter won't print bitmap.

26 views
Skip to first unread message

Newsreader

unread,
Oct 22, 2004, 5:01:41 AM10/22/04
to
Hi,

I have discussed this briefly in an earlier thread, and got no solutions to
it. Now I'm "officially" posting this question and hoping to get an
"official" answer on it.

When I send a bitmap to the Printer object's canvas, the printer will print
nothing. In my earlier post, I mentioned that if I print something on the
Printer's canvas after drawing the bitmap, I will get the Printer to print
the bitmap. I was wrong. The printer will print the line of string (I was
using a string to force the printer to print the bitmap) but no bitmap
printed.

This is what I did:

Graphics::TBitmap *bmp = new Graphics::TBitmap;
TRect rect;
.
.//load the bitmap with some picture,
.//draw some text on it, etc...
.//Set the rect to the size of bmp.
.

TPrinter *printer = Printer();
printer->BeginDoc();
printer->Canvas->Draw(0, 0, bmp);
printer->Canvas->Rectangle(rect); //this time I use a rect to force it
printer->EndDoc();

.
.
.

In the end, the printer printed nothing! Not even the rectangle! So can
someone please tell me what must I do to make the printer print a bitmap??

Thanks in advance.

Regards.


JD

unread,
Oct 22, 2004, 5:41:05 AM10/22/04
to

"Newsreader" <Newsr...@newsgroup.com> wrote:
>
> [...] So can someone please tell me what must I do to make

> the printer print a bitmap??

Untested:

//-------------------------------------------------------------
void __fastcall TForm1::Print1Click(TObject *Sender)
{
if( PrintDialog1->Execute() )
{
Printer()->BeginDoc();
double fPrinterVert = (double) GetDeviceCaps( Printer()->Canvas->Handle, LOGPIXELSY );
double fPrinterHorz = (double) GetDeviceCaps( Printer()->Canvas->Handle, LOGPIXELSX );
double fScreenVert = (double) GetDeviceCaps( Canvas->Handle, LOGPIXELSY );
double fScreenHorz = (double) GetDeviceCaps( Canvas->Handle, LOGPIXELSX );
int iHeight = (int) ((double)pBitmap->Height * (fPrinterVert / fScreenVert));
int iWidth = (int) ((double)pBitmap->Width * (fPrinterHorz / fScreenHorz));
StretchBltBitmap( Printer()->Canvas, 0, 0, iWidth, iHeight, pBitmap );
Printer()->EndDoc();
}
}
//-------------------------------------------------------------
void __fastcall TForm1::StretchBltBitmap(TCanvas *pCanvas, int iX, int iY, int iWidth, int iHeight, Graphics::TBitmap *pBitmap)
{
char* Buffer = NULL;
unsigned int HeaderSize = 0, ImageSize = 0;
GetDIBSizes( pBitmap->Handle, HeaderSize, ImageSize );
try
{
Buffer = new char[ HeaderSize + ImageSize ];
}
catch( Exception& E )
{
MessageDlg( "Error allocating memory for DIB : " + E.Message,
mtError, TMsgDlgButtons() << mbOK, 0 );
return;
}
BITMAPINFO* pBmi = (BITMAPINFO*) Buffer;
unsigned char* pImage = (unsigned char*) Buffer + HeaderSize;
if( GetDIB( pBitmap->Handle, pBitmap->Palette, pBmi, pImage ) )
{
StretchDIBits( pCanvas->Handle, iX, iY, iWidth, iHeight, 0,
0, pBitmap->Width, pBitmap->Height, pImage, pBmi, DIB_RGB_COLORS, SRCCOPY );
}
else
{
MessageDlg( "Error copying the DIB.", mtError,
TMsgDlgButtons() << mbOK, 0 );
}
delete [] Buffer;
}
//-------------------------------------------------------------

~ JD

Joe C. Hecht

unread,
Oct 22, 2004, 1:38:42 PM10/22/04
to
> When I send a bitmap to the Printer object's canvas, the printer will print nothing.

If you ned reliable printing of bitmaps from CBuilder or Delphi, you should really
take a look at our TExcellentImagePrinter product at:

http://www.code4sale.com/joehecht/index.htm


Joe

Delphi, graphics, and printing specialist available - $35/hr
http://www.code4sale.com/codeit/index.htm
Joe Hecht Associates
121 Louise Drive
Crestview, FL 32536


Newsreader

unread,
Oct 22, 2004, 11:00:31 PM10/22/04
to
Thanks for your reply, but I don't accept advertisement. I don't know if
this Newsgroup don't mind ad-posting, but I do know I mind. I'm looking for
a solution to overcome this problem in my own code, not any third party
(commercial or non-commercial) solution. I want to know why Borland team
made a Canvas that is not functioning as other Canvas, and I'd like to know
what's their solution to this problem.

Regards.

"Joe C. Hecht" <joeh...@code4sale.com> wrote in message
news:417945a1$1...@newsgroups.borland.com...

Newsreader

unread,
Oct 23, 2004, 12:07:40 AM10/23/04
to
Hi,

Thanks JD, I've tested the code and it works! So it seems like I'll have to
work on DIB when printing on TPrinter's Canvas... I'm now working on
converting/fitting the code in my application, will keep you informed as I
discover anything new...that is, if you are interested.

Regards.

"JD" <nos...@nospam.com> wrote in message
news:4178d5b1$1...@newsgroups.borland.com...


>
> "Newsreader" <Newsr...@newsgroup.com> wrote:
>
> Untested:
>
> //-------------------------------------------------------------
> void __fastcall TForm1::Print1Click(TObject *Sender)

>.
>.
>.


Joe C. Hecht

unread,
Oct 23, 2004, 5:42:17 PM10/23/04
to
"Newsreader" <Newsr...@newsgroup.com> wrote in message news:4179...@newsgroups.borland.com...

> Thanks for your reply, but I don't accept advertisement. I don't know if
> this Newsgroup don't mind ad-posting, but I do know I mind. I'm looking for
> a solution to overcome this problem in my own code, not any third party
> (commercial or non-commercial) solution. I want to know why Borland team
> made a Canvas that is not functioning as other Canvas, and I'd like to know
> what's their solution to this problem.

Good Luck. There are some TI's and FAQ's on the subject that I wrote when I
worked at Borland, however, if you want the real story, go to my product's site an
read everyting avialable (especially the FAQ) and it may help you understand what
is going on.

Joe
--

0 new messages