How to draw text on TCanvas without white background under painted text?

Alexandr picture Alexandr · Jul 30, 2013 · Viewed 8.1k times · Source

I am writing simple image editor for my project.

There you can see the image in editor:

enter image description here

Above TImage, I placed the few TLabel.

In preview you can see result of drawing TLabels on image:

enter image description here

For drawing 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 result I have the image, where drawed TLabel have white background under text. How to draw TLabel without it?

Answer

Remy Lebeau picture Remy Lebeau · Jul 30, 2013
Img.Canvas.Brush.Style := bsClear;