24 Votes

Delphi/Lazarus: Write text with transparent background on canvas

Tutorial by Guest | Last update on 2021-06-13 | Created on 2014-06-01

Using the function Canvas.TextOut(X, Y, 'Text') I can write an arbitrary text onto the canvas of a bitmap (TBitmap) or a form without any problems.

However, the problem is, that there is automatically drawn a colored background behind the text. It is looking like as if the text was written into a box which is hiding the real background of the canvas.

I can adjust the color for this background using the property Canvas.Brush.Color, but there are enough situations in which this is not suitable. For example whenever I want to write some text on an image or any color gradient. In all of those cases, the colored background is looking very unprofessional.

Therefore, is there any possibility to output the text with a transparent background onto of the canvas?

ReplyPositiveNegative
3Best Answer5 Votes

If you want to write the text with a transparent background, you can set the Brush-Style to bsClear before:

Canvas.Brush.Style := bsClear;
Canvas.TextOut(100, 100, 'Transparent Text');

With this, you should be able to write your text without any problems on backgrounds that are not consisting of only one color.
Last update on 2021-06-13 | Created on 2014-06-01

ReplyPositive Negative
Reply

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile

 

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.