欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

WPF 2D绘图(2)Geometry

发布时间:2023/12/9 58 豆豆
生活随笔 收集整理的这篇文章主要介绍了 WPF 2D绘图(2)Geometry 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

 

Shape是对Geometry的一种封装,Shape本质上还是通过绘制Geometry的形状,然后以填充笔刷来呈现效果

如Rectangle

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF"><Path.Data><RectangleGeometry Rect="30,55 100 30" /></Path.Data></Path>

 

<Rectangle Stroke="Black" StrokeThickness="1" Fill="#CCCCFF" Width="100" Height="30"></Rectangle>

这两者是等价的

Rectangle 是对RectangleGeometry 的封装实现,Rectangle 布局内部将会重写,所以封装了起始点

Geometry(没有笔刷的透明形状)本身无法呈现,必须放在Path容器中才可以

同样的其他的shape也对应Geometry,如果没有的话则以PathGeometry表示.

GeometryGroup

可以同时将多个Geometry放在一起成为一个新的图形

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF"><Path.Data><GeometryGroup FillRule="Nonzero"><LineGeometry StartPoint="10,10" EndPoint="50,30" /><EllipseGeometry Center="40,70" RadiusX="30" RadiusY="30" /> <RectangleGeometry Rect="30,55 100 30" /></GeometryGroup></Path.Data></Path>

 

好比Path是一张画布,代表着一个FrameworkElement。如果使用Shape的话,则需要三个FrameworkElement,这是对性能的挑战.FrameworkElement多的话将会大大降低程序的性能,这时还得采用传统的绘图方法.

即Shape依赖于Geometry

1000个Shape会产生1000个Geometry,但1000个Geometry可以放在1个Shape中,性能不言而喻了

转载于:https://www.cnblogs.com/Clingingboy/archive/2010/11/23/1885124.html

总结

以上是生活随笔为你收集整理的WPF 2D绘图(2)Geometry的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。