zoukankan      html  css  js  c++  java
  • WPF 2D绘图(2)Geometry

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

    image

    如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中,性能不言而喻了

  • 相关阅读:
    golang学习----nil值
    CentOS配置multipath
    oracle基础-创建表空间
    oracle数据库基本命令
    CentOS使用fdisk扩展磁盘空间
    CentOS增加swap分区
    VMWARE错误-"VirtualInfrastructure.Utils.ClientsXml"的类型初始值设定项引发异常
    windows server 2008远程桌面最大连接数设置
    windows sserver 2008远程桌面端口修改
    iSCSI配置
  • 原文地址:https://www.cnblogs.com/Clingingboy/p/1885124.html
Copyright © 2011-2022 走看看