绘制在 RenderTarget.PushAxisAlignedClip() 与 RenderTarget.PopAxisAlignedClip() 之间的内容将被指定的矩形剪辑。

uses Direct2D, D2D1;

procedure TForm1.FormPaint(Sender: TObject);
var
  cvs: TDirect2DCanvas;
  R,RClip: TRect;
begin
  cvs := TDirect2DCanvas.Create(Canvas, ClientRect);

  R := ClientRect;
  InflateRect(R, -ClientWidth div 6, -ClientHeight div 6);

  {设置剪辑区域}
  RClip := R;
  InflateRect(RClip, -ClientWidth div 6, 0);

  cvs.BeginDraw;
  cvs.Pen.Color := clGreen;
  cvs.Brush.Color := clGreen;

  cvs.Ellipse(R); //第一个椭圆

  cvs.RenderTarget.PushAxisAlignedClip(RClip, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); //参数2是抗锯齿的模式
  cvs.Brush.Color := clWhite;
  cvs.Ellipse(R); //第二个椭圆
  cvs.RenderTarget.PopAxisAlignedClip;

  cvs.EndDraw;
  cvs.Free;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  Repaint;
end;


效果图:



posted on 2011-04-03 10:19  万一  阅读(2241)  评论(0编辑  收藏  举报