WPF:获取路径的单点? [英] WPF: Get single points of a Path?
问题描述
我在 WPF 中有一个 Path
并且我想获得这条路径的单点.这有可能吗?(我使用了 WPF 内置的 PathSegment,我想得到 WPF 计算的点数)
I have a Path
in WPF and I'd like to get the single points of this path. Is this somehow possible?
(I used a WPF built-in PathSegment and I'd like to get the points that WPF calculated)
感谢您的提示!
推荐答案
Geometry.GetFlattenedPathGeometry
返回几何对象的多边形近似."然后您可以迭代展平几何图形的图形和线段:每个图形应包含一个 PolyLineSegment
,您可以从中迭代 Points 属性以获取路径上的点.因此:
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);
这篇关于WPF:获取路径的单点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!