System.Windows.Media 命名空间


.NET Framework 类库
CombinedGeometry 类

更新:2007 年 11 月

表示由两个 Geometry 对象组合定义的二维几何形状。

命名空间:  System.Windows.Media
程序集:  PresentationCore(在 PresentationCore.dll 中)
用于 XAML 的 XMLNS:http://schemas.microsoft.com/winfx/xaml/presentation

语法

Visual Basic(声明)
Public NotInheritable Class CombinedGeometry _
    Inherits Geometry
Visual Basic (用法)
Dim instance As CombinedGeometry
C#
public sealed class CombinedGeometry : Geometry
Visual C++
public ref class CombinedGeometry sealed : public Geometry
J#
public final class CombinedGeometry extends Geometry
JScript
public final class CombinedGeometry extends Geometry
XAML 对象元素用法
<CombinedGeometry .../>
备注

GeometryCombineMode 属性指定如何组合两个几何图形。请注意,CombinedGeometry 组合两个几何图形指定的区域,所以没有区域(例如 LineGeometry)的几何图形将在组合后消失。

几何图形可通过以下几种方式组合:使用 GeometryGroupCombinedGeometryGeometry 类的 Combine 方法。

  • GeometryGroup 使用一个或多个 Geometry 对象创建复合几何图形。

  • CombinedGeometry 使用指定的布尔操作组合由两个 Geometry 对象所描述的区域。

  • Geometry 类的静态 Combine 方法与 CombinedGeometry 对象具有完全相同的行为方式。

使用 CombinedGeometry 执行联合操作时要谨慎,因为它会占用大量的 CPU 资源。大多数情况下,使用 GeometryGroupAddGeometry 的效果更佳。

仅当存在下列情况之一时,才使用 CombinedGeometry

  • 几何图形操作不是一个联合。

  • 两个几何图形中有一个的 FillRule 值是 EvenOdd,并且两个几何图形都是自相交的(即 FillRule 实际会产生影响)。

  • 时间不是问题,但需要注意空间的使用(例如,如果几何图形只被创建一次并进行缓存)。通常情况下,CombinedGeometry 生成的输出小于 AddGeometry

  • 生成的几何图形将被绘制或用于路径动画,且 AddGeometry 并不提供所需的轮廓。

Freezable 功能

CombinedGeometry 是一种 Freezable 对象。有关 Freezable 功能(例如冻结和克隆)的信息,请参见 Freezable 对象概述

示例

此示例演示如何组合几何图形。若要组合两个几何图形,请使用 CombinedGeometry 对象。对要组合的两个几何图形,设置该对象的 Geometry1Geometry2 属性,并将 GeometryCombineMode 属性(确定如何将这两个几何图形组合在一起)设置为 UnionIntersectExcludeXor

若要通过两个或两个以上的几何图形创建复合几何图形,可使用 GeometryGroup

在下面的示例中,用 Exclude 几何图形组合模式定义了一个 CombinedGeometryGeometry1Geometry2 定义为半径相同的圆,但是中心偏离 50。

C#
<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
  <Path.Data>

    <!-- Combines two geometries using the exclude combine mode. -->
    <CombinedGeometry GeometryCombineMode="Exclude">
      <CombinedGeometry.Geometry1>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" />
      </CombinedGeometry.Geometry1>
      <CombinedGeometry.Geometry2>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,75" />
      </CombinedGeometry.Geometry2>
    </CombinedGeometry>
  </Path.Data>
</Path>
使用 Exclude 模式组合的几何图形

“排除”组合模式的结果

在下面的标记中,用 Intersect 组合模式定义了一个 CombinedGeometryGeometry1Geometry2 定义为半径相同的圆,但是中心偏离 50。

C#
<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
  <Path.Data>

    <!-- Combines two geometries using the intersect combine mode. -->
    <CombinedGeometry GeometryCombineMode="Intersect">
      <CombinedGeometry.Geometry1>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" />
      </CombinedGeometry.Geometry1>
      <CombinedGeometry.Geometry2>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,75" />
      </CombinedGeometry.Geometry2>
    </CombinedGeometry>
  </Path.Data>
</Path>
使用 Intersect 模式组合的几何图形

“相交”组合模式的结果

在下面的标记中,用 Union 组合模式定义了一个 CombinedGeometryGeometry1Geometry2 定义为半径相同的圆,但是中心偏离 50。

C#
<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
  <Path.Data>

    <!-- Combines two geometries using the union combine mode. -->
    <CombinedGeometry GeometryCombineMode="Union">
      <CombinedGeometry.Geometry1>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" />
      </CombinedGeometry.Geometry1>
      <CombinedGeometry.Geometry2>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,75" />
      </CombinedGeometry.Geometry2>
    </CombinedGeometry>
  </Path.Data>
</Path>
使用 Union 模式组合的几何图形

“联合”组合模式的结果

在下面的标记中,用 Xor 组合模式定义了一个 CombinedGeometryGeometry1Geometry2 定义为半径相同的圆,但是中心偏离 50。

C#
<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
  <Path.Data>

    <!-- Combines two geometries using the XOR combine mode. -->
    <CombinedGeometry GeometryCombineMode="Xor">
      <CombinedGeometry.Geometry1>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" />
      </CombinedGeometry.Geometry1>
      <CombinedGeometry.Geometry2>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,75" />
      </CombinedGeometry.Geometry2>
    </CombinedGeometry>
  </Path.Data>
</Path>
使用 Xor 模式组合的几何图形

Xor 组合模式的结果
继承层次结构

System..::.Object
  System.Windows.Threading..::.DispatcherObject
    System.Windows..::.DependencyObject
      System.Windows..::.Freezable
        System.Windows.Media.Animation..::.Animatable
          System.Windows.Media..::.Geometry
            System.Windows.Media..::.CombinedGeometry
线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.5、3.0
另请参见

参考

其他资源

标记 :


Page view tracker