Recent

Author Topic: [solved] Prevent Canvas.TextOut from erasing everything behind the text  (Read 1173 times)

PunyDog

  • Newbie
  • Posts: 6
I wanted to put a text over a picture, but when I used Canvas.TextOut, there was a white square block around the text. I tried to look for anything about transparency or something like that but unable to find any. Can anyone help?
« Last Edit: April 18, 2023, 09:37:28 am by PunyDog »

dsiders

  • Hero Member
  • *****
  • Posts: 1594
Re: Canvas.TextOut erase everything behind the text
« Reply #1 on: April 18, 2023, 07:50:52 am »
I wanted to put a text over a picture, but when I used Canvas.TextOut, there was a white square block around the text. I tried to look for anything about transparency or something like that but unable to find any. Can anyone help?

Did you try setting TCanvas.TextStyle.Opaque to False before calling TextOut?
https://lazarus-ccr.sourceforge.io/docs/lcl/graphics/ttextstyle.html

PunyDog

  • Newbie
  • Posts: 6
Re: Canvas.TextOut erase everything behind the text
« Reply #2 on: April 18, 2023, 09:18:59 am »
I tried that, but it gave error : Argument cannot be assigned to

AlexTP

  • Hero Member
  • *****
  • Posts: 2696
    • UVviewsoft
Re: Canvas.TextOut erase everything behind the text
« Reply #3 on: April 18, 2023, 09:31:34 am »
Run:
        Canvas.Brush.Style:= bsClear;

Before Canvas.TextOut.

PunyDog

  • Newbie
  • Posts: 6
Re: Canvas.TextOut erase everything behind the text
« Reply #4 on: April 18, 2023, 09:35:37 am »
Run:
        Canvas.Brush.Style:= bsClear;

Before Canvas.TextOut.

Hey, it works. Thank you!
Wonder why they put it with brushstyle, though    %)

paweld

  • Hero Member
  • *****
  • Posts: 1596
An example of using TTextStyle
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var
  3.   ts: TTextStyle;
  4.   s: String;
  5. begin
  6.   s := 'Sample text' + LineEnding + 'in a' + LineEnding + 'few lines';
  7.   ts.Opaque := False;
  8.   ts.Wordbreak := True;
  9.   ts.SingleLine := False;
  10.   ts.Alignment := taLeftJustify;
  11.   ts.Layout := tlTop;
  12.   Canvas.TextRect(ClientRect, 100, 100, s, ts);
  13. end;
  14.  
Best regards / Pozdrawiam
paweld

wp

  • Hero Member
  • *****
  • Posts: 13485
Re: Canvas.TextOut erase everything behind the text
« Reply #6 on: April 18, 2023, 11:02:54 am »
Wonder why they put it with brushstyle, though    %)
Well, I think it's quite logical. Brush defines the fill of the background. Why shouldn't this apply to the text as well?

PunyDog

  • Newbie
  • Posts: 6
Re: Canvas.TextOut erase everything behind the text
« Reply #7 on: April 18, 2023, 11:19:14 am »
Wonder why they put it with brushstyle, though    %)
Well, I think it's quite logical. Brush defines the fill of the background. Why shouldn't this apply to the text as well?

At least, it's not so *clear* to me  :P

 

TinyPortal © 2005-2018