WPF-2D图形(二)Geometry几何体

Geometry有很多子类,可以分成基本几何体(basic geometry)和聚合几何体(aggregate geometry)。

-------------------------------------------------------------------------------------------------------------------------------------------------------

基本几何体分类

1、RectangleGeometry

包括定义尺寸的Rect类,和圆角的X,Y轴的半径,RadiusX和RadiusY。

2、EllipseGeometry

包括RadiusX和RadiusY和Center(中心点)属性。

3、LineGeometry

包括StartPoint(开始点)和EndPoint(结束点)。

4、PathGeometry

在它的Figure(轮廓)内容属性中包含一组PahtFigure对象的集合。

前面三种几何体是PathGeometry的特例,可以用PathGeometry表示任何几何体。

--------------------------------------------------------------------------------------------------------------------------------------------------------

PathGeometry是最强大的画几何类,重点说下它

PahtGeometry包括PathFigure和PathSegment。这两个都是集合。

每一个PathFigure包含一个或多个连接起来的PathSegment。PathSegment仅仅是一个线段,它有7个派生类。

1、LineSegment

用于表示线段的类。

2、PolyLineSegment

用于表示线段连接顺序的快捷方式

3、ArcSegment

用于表示假想的椭圆上周线上的曲线段的类。

4、BezierSegment

用于表示三次贝塞尔曲线段的类

5、PolyBezierSegment

用于表示一组BezierSegment的连接顺序的快捷方式

6、QuadraticBezierSegment

用于表示二次贝塞尔曲线段的类

7、PolyQuadraticBezierSegment

用于表示一组QuadraticSegment的连接顺序的快捷方式

-----------------------------------------------------------------------------------------------------------------------------------

开始举例子了

<Image>
    <Image.Source>
          <DrawingImage>
                <DrawingImage.Drawing>
                      <GeometryDrawing>
                            <GeometryDrawing.Pen>
                                <Pen Brush="Black" Thickness="10"></Pen>
                            </GeometryDrawing.Pen>
                            <GeometryDrawing.Geometry>
                                <PathGeometry>
                                    <PathFigure>
                                        <LineSegment Point="0,100"></LineSegment>
                                        <LineSegment Point="100,100"></LineSegment>
                                    </PathFigure>
                                </PathGeometry>
                            </GeometryDrawing.Geometry>
                        </GeometryDrawing>
                 </DrawingImage.Drawing>
            </DrawingImage>
       </Image.Source>
 </Image>

这里画了一个L,两条直线;LineSegment仅有一个point属性,记录结束点的坐标;起始点的坐标,第一条线默认是0,0,其他线的默认是上一条线的结束点。这样就自动把所有直线连接上了。

如果要自定义起始点,在PathFigure加个属性StartPoint="10,10"。

在讨论下GeometryDrawing.Brush是否对这个例子有效。

在GeometryDrawing加个属性Brush=“Red”;颜色填充了PathFigure,PathFigure其实是封闭的,只是这条封闭了这个几何体的线是否显示的问题。

让这条封闭线显示出来。有两种方法,直接再补一条point值等于Pathfigureqi起始点的LineSegment;或者给PahtFigure加个属性IsClosed="True"。

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

PathGeometry的PathFigure是一个集合,可以包括多个几何体形成组合。

原文地址:https://www.cnblogs.com/snake1118/p/12692971.html