{相關方法}
TDirect2DCanvas.RenderTarget.SetAntialiasMode();
TDirect2DCanvas.RenderTarget.GetAntialiasMode;
{相關常量}
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE = 0;
D2D1_ANTIALIAS_MODE_ALIASED = 1;
測試代碼:
uses Direct2D, D2D1;
procedure TForm1.FormCreate(Sender: TObject);
begin
CheckBox1.Caption := 'D2D1_ANTIALIAS_MODE_PER_PRIMITIVE';
CheckBox1.Checked := True;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
const
sArr: array[Boolean] of string = ('D2D1_ANTIALIAS_MODE_PER_PRIMITIVE', 'D2D1_ANTIALIAS_MODE_ALIASED');
begin
CheckBox1.Caption := sArr[not CheckBox1.Checked];
Refresh;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
cvs: TDirect2DCanvas;
rect: TRect;
begin
cvs := TDirect2DCanvas.Create(Canvas, ClIEntRect);
cvs.Pen.Color := clRed;
cvs.Pen.Width := 25;
if CheckBox1.Checked then
cvs.RenderTarget.SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE)
else
cvs.RenderTarget.SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
//cvs.RenderTarget.SetAntialiasMode(Integer(not CheckBox1.Checked)); 可用該行代替上面四行
rect := ClIEntRect;
InflateRect(rect, -ClientWidth div 5, -ClIEntHeight div 5 );
OffsetRect(rect, 0, 10);
cvs.BeginDraw;
cvs.Ellipse(rect);
cvs.EndDraw;
cvs.Free;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
Repaint;
end;
效果圖: