绘制在 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;
效果图: