How to draw text on TCanvas without a white background under the drawn text?

I am writing a simple image editor for my project.

Here you can see the image in the editor:

enter image description here

Above TImage I put some TLabel.

In the preview, you can see the result of drawing TLabels in the image:

enter image description here

To draw TLabels, I wrote this code:

procedure TPrintForm.BuildPreview(aSsignTo: TImage); var Img: TBitmap; i: Integer; begin Img := TBitmap.Create; try Img.Assign(fSrcBitmap); for i := 0 to Count - 1 do begin Img.Canvas.Font := Items[i].Text.Font; Img.Canvas.TextOut(Items[i].Text.BoundsRect.TopLeft.X - Items[i].Text.Font.Size, Items[i].Text.BoundsRect.TopLeft.Y - Items[i].Text.Height - Items[i].Text.Font.Size, Items[i].Text.Caption); end; aSsignTo.Picture.Assign(Img); finally FreeAndNil(Img); end; end; 

As a result, I have an image where the highlighted TLabel has a white background under the text. How to draw a TLabel without it?

+6
source share
2 answers

Thanks everyone for the answers. I found a solution here:

 SetBkMode(Img.Picture.Bitmap.Canvas.Handle,TRANSPARENT); 

The problem is resolved.

+4
source
 Img.Canvas.Brush.Style := bsClear; 
+15
source

Source: https://habr.com/ru/post/950664/


All Articles