Direct2D (6) : 绘制质量(设置抗锯齿模式)

Direct2D (6) : 绘制质量(设置抗锯齿模式)


{相关方法}
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;


效果图:

Direct2D (6) : 绘制质量(设置抗锯齿模式)

posted on 2011-04-01 00:02  万一  阅读(4648)  评论(10)  编辑  收藏
上一篇:Direct2D (4) : DrawGeometry() 与 FillGeometry()


下一篇:Direct2D (11) : 画刷之 ID2D1LinearGradientBrush