delphifiremonkeydelphi-xe8tcanvas

Set font color in FMX TCanvas


Not sure if I'm missing something here but are you able to set font color in Firemonkey TCanvas?

I don't see anything to suggest this in the following property:

Canvas.Font. ????

Any help would be great

Thanks,


Solution

  • Test this code. put an Image on the form and a button.

    procedure TForm1.Button1Click(Sender: TObject);
    var
      b:TBitmap;
      f:TFont;
    begin
      b:=TBitmap.Create;
      f:=TFont.Create;
      try
        f.Family:='Arial';
        f.Size:=20;
        f.Style:=[TFontStyle.fsBold];
        b.Width:=200;
        b.Height:=200;
        b.Canvas.BeginScene;
        b.Canvas.Fill.Color:=TAlphaColorRec.red;
        b.Canvas.Font.Assign(f);
        b.Canvas.FillText(TRectF.Create(0,0,100,100),'AAA',False,1,[TFillTextFlag.RightToLeft], TTextAlign.Leading,TTextAlign.Center);
        b.Canvas.EndScene;
        image1.Bitmap:=b;
      finally
       b.Free;
       f.Free;
      end;
    end;