Ant*_*ner 1 delphi fonts firemonkey firemonkey-fm2
我有一些代码可以绘制放置在TImage顶部的一组控件。然后,我抓住TImage的MakeScreenshot来保存文件。现在,它可以完美运行。我现在正在努力的是更改一个或多个标签/文本样式控件的字体属性。不管我尝试什么,标签都不会改变。下面是我的示例代码:
procedure TfrmSnapshot.Process;
var
LRect1, LRect2, LRect3, LRect4: TRectF;
X, Y, W, H: Integer;
begin
//
X := Round(Label1.Position.X);
Y := Round(Label1.Position.Y);
W := Round(X + Label1.Width);
H := Round(Y + Label1.Height);
LRect1.Create(X, Y, W, H);
X := Round(Label2.Position.X);
Y := Round(Label2.Position.Y);
W := Round(X + Label2.Width);
H := Round(Y + Label2.Height);
LRect2.Create(X, Y, W, H);
X := Round(Label3.Position.X);
Y := Round(Label3.Position.Y);
W := Round(X + Label3.Width);
H := Round(Y + Label3.Height);
LRect3.Create(X, Y, W, H);
X := Round(Rect1.Position.X);
Y := Round(Rect1.Position.Y);
W := Round(X + Rect1.Width);
H := Round(Y + Rect1.Height);
LRect4.Create(X, Y, W, H);
Label1.Text := fTitle;
Label1.Font.Size := 40.0;
Label2.Text := fSub;
Label3.Text := fSite;
With imgSnap.Bitmap Do
Begin
Label1.Font.Size = 40; //Does not work
Label1.Font.Family = 'Arial'; //Does not work
Label1.PaintTo(Canvas, LRect1);
Label2.PaintTo(Canvas, LRect2);
Label3.PaintTo(Canvas, LRect3);
Rect1.PaintTo(Canvas, LRect4);
End;
imgSnap.MakeScreenshot.SaveToFile('test.jpg');
end;
Run Code Online (Sandbox Code Playgroud)
如何设置标签的字体,以使其正确绘制并包含在屏幕截图中?
问候安东尼
在firemonkey TLabel属性中设置Font.Family和Font.Size的样式。如果要在代码中更改字体大小或字体,则需要在此属性上禁用样式。要更改此设置,请正确设置属性StyledSettings。
例:
Label1.StyledSettings:=Label1.StyledSettings -[TStyledSetting.ssFamily,TStyledSetting.ssSize]
Run Code Online (Sandbox Code Playgroud)