现在的位置: 首页 > 综合 > 正文

Sliverlight中使用Path绘制复杂几何图形

2012年04月25日 ⁄ 综合 ⁄ 共 1129字 ⁄ 字号 评论关闭

转自http://www.riafan.com/article/silverlight/draw-with-path.html

在Sliverlight中,Path绘图是最灵活的,可以创建更复杂的几何图形。Path绘图有两种方法:使用Mini-Language Path或创建PathGeometry对象。下面我们就用这两种方法绘制两段椭圆弧线。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<StackPanel odientation="Horizontal">
    <!--Mini-Language Path绘制椭圆弧线-->
    <Path Stroke="Blue" StrokeThickness="2"
            Data="M 10,100 A 50,25,0,1,1 100,100"/>
    <!--PathGeometry绘制椭圆弧线-->
    <Path Stroke="Blue" StrokeThickness="2">
        <Path.Data>
            <PathGeometry>
                <PathFigure
                    StartPoint="10,100">
                    <ArcSegment Point="100,100"
                        Size="50,25" RotationAngle="0"
                        IsLargeArc="True" SweepDirection="Clockwise" />
                </PathFigure>
            </PathGeometry>
        </Path.Data>
    </Path>
</StackPanel>

不难看出,使用Mini-Language Path语法会简洁些,但没有PathGeometry对象好理解。移动命令M对应StartPoint属性,绘制命令A对应ArcSegment对象, 绘制命令A中的参数和ArcSegment对象的属性是一一对应的,所以最终显示效果一样。

从本质讲,Path也是Shape对象,但使用Path可创建比其他Shape对象更复杂的二维图形。Path还可以作为一个绘图的容器,它允许容纳任何形状的Geometry成员对象包含在Path.Data属性中。

不知大家有没有注意到,Flex 4中的Path绘图和Sliverlight中的相似,都可以使用mini-language语法,不过Flex 4中不支持椭圆弧线命令(A)。

 

抱歉!评论已关闭.