先看一张图:HQ-0 是简单设置 Form 的 Quality 为 HighQuality 的结果,HQ-1 是做了进一步设置的结果,DQ 是默认的效果,大家可以看到,HQ-0 和默认的没有抗锯齿的效果没啥区别。
那么,问题的关键在那里呢?
问题的关键就在你设置完品质选项后,还需要调用一个函数,缺少它,更改品质的代码不会起作用。
uses FMX.Context.GLES.Android; ... TCustomAndroidContext.RecreateSharedContext;//在更改完品质属性后需要调用这句,FMX默认没调用,所以没启作用
好了,加上这句代码重建共享的上下文后,你的窗体上所有的东西就会抗锯齿了。
下面是一段测试的源码,在界面上旋转一个按钮,一个 Label 和一个 CheckBox,然后在按钮的 OnClick 和 Form 的 OnPaint 添加下面的代码:
unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects, FMX.Controls.Presentation, FMX.StdCtrls; type TForm1 = class(TForm) btnChangeQuality: TButton; Label1: TLabel; CheckBox1: TCheckBox; procedure Button1Click(Sender: TObject); procedure FormPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses FMX.Context.GLES.Android; {$R *.fmx} procedure TForm1.Button1Click(Sender: TObject); begin if Quality = TCanvasQuality.HighPerformance then Quality := TCanvasQuality.HighQuality else Quality := TCanvasQuality.HighPerformance; case Quality of TCanvasQuality.SystemDefault: Label1.Text := 'Default'; TCanvasQuality.HighPerformance: Label1.Text := 'HighPerformance'; TCanvasQuality.HighQuality: Label1.Text := 'HighQuality'; end; if CheckBox1.IsChecked then TCustomAndroidContext.RecreateSharedContext; Invalidate; end; procedure TForm1.FormPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF); begin Canvas.BeginScene(); try Canvas.StrokeThickness := 20; Canvas.Stroke.Color := TAlphaColors.Black; Canvas.Stroke.Kind := TBrushKind.Solid; Canvas.DrawLine(PointF(0, 0), PointF(Width, Height), 1); finally Canvas.EndScene; end; end; end.
然后,在手机上运行程序,分别在 HighPerformance 模式下,选中 CheckBox,然后再点击 Button 切换到 HighQuality 模式,就能看出效果的对比了。