## Direct2D (24) : 合并几何对象 转

涂孟超

``````uses Direct2D, D2D1;

procedure TForm1.FormPaint(Sender: TObject);
var
cvs: TDirect2DCanvas;
iEllipseGeometry1, iEllipseGeometry2: ID2D1EllipseGeometry;
iGeometrySink: ID2D1GeometrySink;
iPathGeometry1,iPathGeometry2,iPathGeometry3,iPathGeometry4: ID2D1PathGeometry;
ptCenter: TD2DPoint2f;
r: Single;
matrix: TD2DMatrix3x2F;
begin
ptCenter := D2D1PointF(100, 100);
r := 50;
matrix := TD2DMatrix3x2F.Identity;

{两个源对象}
D2DFactory.CreateEllipseGeometry(D2D1Ellipse(ptCenter, r, r), iEllipseGeometry1);
ptCenter.x := ptCenter.x + r;
D2DFactory.CreateEllipseGeometry(D2D1Ellipse(ptCenter, r, r), iEllipseGeometry2);

{UNION 运算}
D2DFactory.CreatePathGeometry(iPathGeometry1);
iPathGeometry1.Open(iGeometrySink);
iEllipseGeometry1.CombineWithGeometry(iEllipseGeometry2, D2D1_COMBINE_MODE_UNION, matrix, 0, iGeometrySink);
iGeometrySink.Close;

{INTERSECT 运算}
D2DFactory.CreatePathGeometry(iPathGeometry2);
iPathGeometry2.Open(iGeometrySink);
iEllipseGeometry1.CombineWithGeometry(iEllipseGeometry2, D2D1_COMBINE_MODE_INTERSECT, matrix, 0, iGeometrySink);
iGeometrySink.Close;

{XOR 运算}
D2DFactory.CreatePathGeometry(iPathGeometry3);
iPathGeometry3.Open(iGeometrySink);
iEllipseGeometry1.CombineWithGeometry(iEllipseGeometry2, D2D1_COMBINE_MODE_XOR, matrix, 0, iGeometrySink);
iGeometrySink.Close;

{EXCLUDE 运算}
D2DFactory.CreatePathGeometry(iPathGeometry4);
iPathGeometry4.Open(iGeometrySink);
iEllipseGeometry1.CombineWithGeometry(iEllipseGeometry2, D2D1_COMBINE_MODE_EXCLUDE, matrix, 0, iGeometrySink);
iGeometrySink.Close;

cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
cvs.BeginDraw;
cvs.Pen.Color := clWebCornFlowerBlue;
cvs.Brush.Color := clWebCornFlowerBlue;
cvs.Brush.Handle.SetOpacity(0.75);

cvs.FillGeometry(iPathGeometry1);
cvs.DrawGeometry(iEllipseGeometry1);
cvs.DrawGeometry(iEllipseGeometry2);

cvs.RenderTarget.SetTransform(TD2DMatrix3x2F.Translation(180, 0));
cvs.FillGeometry(iPathGeometry2);
cvs.DrawGeometry(iEllipseGeometry1);
cvs.DrawGeometry(iEllipseGeometry2);

cvs.RenderTarget.SetTransform(TD2DMatrix3x2F.Translation(180*2, 0));
cvs.FillGeometry(iPathGeometry3);
cvs.DrawGeometry(iEllipseGeometry1);
cvs.DrawGeometry(iEllipseGeometry2);

cvs.RenderTarget.SetTransform(TD2DMatrix3x2F.Translation(180*3, 0));
cvs.FillGeometry(iPathGeometry4);
cvs.DrawGeometry(iEllipseGeometry1);
cvs.DrawGeometry(iEllipseGeometry2);

cvs.EndDraw;
cvs.Free;
end;``````

``````uses Direct2D, D2D1;

procedure TForm1.FormPaint(Sender: TObject);
var
cvs: TDirect2DCanvas;
iEllipseGeometry1, iEllipseGeometry2: ID2D1EllipseGeometry;
iGeometrySink: ID2D1GeometrySink;
iPathGeometrys: array[0..3] of ID2D1PathGeometry;
ptCenter: TD2DPoint2f;
r: Single;
i: Integer;
begin
ptCenter := D2D1PointF(100, 100);
r := 50;

D2DFactory.CreateEllipseGeometry(D2D1Ellipse(ptCenter, r, r), iEllipseGeometry1);
ptCenter.x := ptCenter.x + r;
D2DFactory.CreateEllipseGeometry(D2D1Ellipse(ptCenter, r, r), iEllipseGeometry2);

for i := 0 to 3 do
begin
D2DFactory.CreatePathGeometry(iPathGeometrys[i]);
iPathGeometrys[i].Open(iGeometrySink);
iEllipseGeometry1.CombineWithGeometry(iEllipseGeometry2, i, TD2DMatrix3x2F.Identity, 0, iGeometrySink);
iGeometrySink.Close;
end;

cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
cvs.BeginDraw;
cvs.Pen.Color := clWebCornFlowerBlue;
cvs.Brush.Color := clWebCornFlowerBlue;
cvs.Brush.Handle.SetOpacity(0.75);

for i := 0 to 3 do
begin
cvs.RenderTarget.SetTransform(TD2DMatrix3x2F.Translation(180*i, 0));
cvs.FillGeometry(iPathGeometrys[i]);
cvs.DrawGeometry(iEllipseGeometry1);
cvs.DrawGeometry(iEllipseGeometry2);
end;

cvs.EndDraw;
cvs.Free;
end;``````

### 涂孟超

Direct2D教程（十）绘制文本

2017/10/17
0
0

2013/10/08
0
0

Dy_
2014/01/16
8.2K
10
Direct2D教程（十一）几何变换

2017/09/12
0
0
postgis常用函数（99%转载 1%原创）

1,基本操作函数 AddGeometryColumn(<schemaname>, <tablename>, <columnname>, <srid>, <type>, <dimension>) 给一个已存在属性数据表增加一个几何字段(geomtry column)。schemaname 指表的模......

2013/01/07
0
0

1.背景介绍 异常检测可以定义为“基于行动者（人或机器）的行为是否正常作出决策”，这项技术可以应用于非常多的行业中，比如金融场景中做交易检测、贷款检测；工业场景中做生产线预警；安防...

15分钟前
1
0
DecimalFormat 类基本使用

/* * DecimalFormat 类主要靠 # 和 0 两种占位符号来指定数字长度 * 0 表示如果位数不足则以 0 填充 * # 表示只要有可能就把数字拉上这个位置 * */ public static void main(String[] args){...

32分钟前
3
0
This APT has Super Cow Powers.

49分钟前
2
0

58分钟前
6
0

1
0