Board index » delphi » Drawing transparent text using tcanvas.textout?

Drawing transparent text using tcanvas.textout?

I'm using tcanvas.textout to draw text onto a bitmap, but can't figure out
how to draw only the text, and not the background bounding box that seems to
come with it.  The docs offer no help on the subject.  I'd rather avoid the
'draw it to a temporary buffer first' workaround for performance reasons.

The code snippet:

Quote

          MyBitmap.Canvas.Font.Name:='Times New Roman';
          MyBitmap.Canvas.Font.Height:=24;
          MyBitmap.Canvas.Font.Color:=clRed;
          MyBitmap.Canvas.Textout(10,10,"Hello World");
<<
Produces the proper text, but it appears in a black box--I need to avoid
this.  Any help would be greatly appreaciated.

Thanks,
Matt

 

Re:Drawing transparent text using tcanvas.textout?


try to set the Canvas.CopyMode.
I don't know exactly the value you have to put (look in help), but if I
remember right from old DOS days, you have to use Boolean XOR.
I didn't try it, so I'm not sure if will work.

-ioan

Quote
"Matt" <spamtrash...@gruson.net> wrote in message news:3bec3464_1@dnews...
> I'm using tcanvas.textout to draw text onto a bitmap, but can't figure out
> how to draw only the text, and not the background bounding box that seems
to
> come with it.  The docs offer no help on the subject.  I'd rather avoid
the
> 'draw it to a temporary buffer first' workaround for performance reasons.

> The code snippet:

>           MyBitmap.Canvas.Font.Name:='Times New Roman';
>           MyBitmap.Canvas.Font.Height:=24;
>           MyBitmap.Canvas.Font.Color:=clRed;
>           MyBitmap.Canvas.Textout(10,10,"Hello World");
> <<
> Produces the proper text, but it appears in a black box--I need to avoid
> this.  Any help would be greatly appreaciated.

> Thanks,
> Matt

Re:Drawing transparent text using tcanvas.textout?


This will work

          MyBitmap.Canvas.Font.Name:='Times New Roman';
          MyBitmap.Canvas.Font.Height:=24;
          MyBitmap.Canvas.Font.Color:=clRed;

          MyBitmap.Canvas.Brush.Style := bsClear;
          MyBitmap.Canvas.Textout(10,10,"Hello World");
          MyBitmap.Canvas.Brush.Style := bsSolid;

cu Christian Schneider

Re:Drawing transparent text using tcanvas.textout?


Quote
Matt wrote:
> I'm using tcanvas.textout to draw text onto a bitmap, but can't figure out
> how to draw only the text, and not the background bounding box that seems to
> come with it.  The docs offer no help on the subject.  I'd rather avoid the
> 'draw it to a temporary buffer first' workaround for performance reasons.

> The code snippet:

>           MyBitmap.Canvas.Font.Name:='Times New Roman';
>           MyBitmap.Canvas.Font.Height:=24;
>           MyBitmap.Canvas.Font.Color:=clRed;
>           MyBitmap.Canvas.Textout(10,10,"Hello World");
> <<
> Produces the proper text, but it appears in a black box--I need to avoid
> this.  Any help would be greatly appreaciated.

Set the Canvas.Brush style to bsClear.

MyBitmap.Canvas.Brush.Style := bsClear;

Set it back to bsSolid if you need to fill an area.

The brush is the object used for the background.  When you want to set the
background color or fill color, set the Brush.Color.

Other Threads