WPF: Get single points of a Path?

蓝咒 提交于 2019-11-30 15:49:08
itowlson

Geometry.GetFlattenedPathGeometry returns "a polygonal approximation of the Geometry object." You can then iterate over the figures and segments of the flattened Geometry: each figure should consist of a single PolyLineSegment, from which you can iterate over the Points property to get the points along the path. Thus:

  PathGeometry g = Path.Data.GetFlattenedPathGeometry();

  foreach (var f in g.Figures)
    foreach (var s in f.Segments)
      if (s is PolyLineSegment)
        foreach (var pt in ((PolyLineSegment)s).Points)
          Debug.WriteLine(pt);
WhiteN01se

In WPF4 there is also the method GetPointAtFractionLength, which lets you get the coordinates of any point and its tangent vector along the length of the path ranging from 0.0 - 1.0.

Very handy to "sample" an arbitrary amount of points along a path.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!