Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 857
Alexandr Avatar asked Jul 30 '13 21:07

Alexandr


2 Answers

Img.Canvas.Brush.Style := bsClear;
like image 105
Remy Lebeau Avatar answered Nov 12 '22 10:11

Remy Lebeau


Thanks to all for answers. I found solution here:

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

Problem resolved.

like image 38
Alexandr Avatar answered Nov 12 '22 10:11

Alexandr