您可以获得 CombinedGeometry 或 GeometryGroup 对象的路径标记语法吗?
Can you get the path markup syntax for a CombinedGeometry or a GeometryGroup object?
在处理 PathGeometry
对象时,如果您调用 ToString()
,您将返回表示路径的 'path markup syntax'。然而,对于 GeometryGroup
和 CombinedGeometry
.
则不同。
考虑以下代码:
var hBar = Geometry.Parse("F1M10,20L40,20L40,30L10,30z");
var vBar = Geometry.Parse("F1M20,10L30,10L30,40L20,40z");
var cross = Geometry.Parse("F1M20,10L20,10L30,10L30,20L40,20L40,30L30,30L30,40L20,40L20,30L10,30L10,20L20,20z");
var combined = new GeometryGroup(){ FillRule = FillRule.Nonzero };
combined.Children.Add(hBar);
combined.Children.Add(vBar);
var union = new CombinedGeometry(GeometryCombineMode.Union, HBar.Geometry, VBar.Geometry);
Console.WriteLine($"hBar : {hBar}");
Console.WriteLine($"vBar : {vBar}");
Console.WriteLine($"cross : {cross}");
Console.WriteLine($"combined : {combined}");
Console.WriteLine($"union : {union}");
图片如下:
代码输出如下:
hBar : F1M10,20L40,20 40,30 10,30z
vBar : F1M20,10L30,10 30,40 20,40z
cross : F1M20,10L20,10 30,10 30,20 40,20 40,30 30,30 30,40 20,40 20,30 10,30 10,20 20,20z
combined : System.Windows.Media.GeometryGroup
union : System.Windows.Media.CombinedGeometry
我希望得到 CombinedGeometry
和 GeometryGroup
对象的路径标记语法。例如,特别是在 'union' 的情况下,我希望找回类似于 cross
条目的内容。
(* 注意:我不关心顶点的顺序或绘图方向,只要它显示为相同 shape/path。)
这是有关 Path Markup Syntax 的 Microsoft 页面。这是我要获取的格式。
这可能吗?
也许我没有抓住要点,但恢复路径非常简单...
foreach(var child in combined.Children)
{
Console.WriteLine($" child of combined = {child.ToString()}");
}
Console.WriteLine($" union.Geometry1 = {union.Geometry1}");
Console.WriteLine($" union.Geometry2 = {union.Geometry2}");
产生...
child of combined = F1M10,20L40,20 40,30 10,30z
child of combined = F1M20,10L30,10 30,40 20,40z
union.Geometry1 = F1M10,20L40,20 40,30 10,30z
union.Geometry2 = F1M20,10L30,10 30,40 20,40z
是的,只是展平几何体。但是请注意,此 returns 是几何体的多边形表示。
union.GetFlattenedPathGeometry().ToString()
为了保持原始曲线,为此似乎有许多内置变化,我将它们留在这里供以后的读者使用。
PathGeometry.CreateFromGeometry(combined).ToString()
PathGeometry.CreateFromGeometry(union).ToString()
Geometry.Combine(hBar, vBar, GeometryCombineMode.Union, null).ToString()
在处理 PathGeometry
对象时,如果您调用 ToString()
,您将返回表示路径的 'path markup syntax'。然而,对于 GeometryGroup
和 CombinedGeometry
.
考虑以下代码:
var hBar = Geometry.Parse("F1M10,20L40,20L40,30L10,30z");
var vBar = Geometry.Parse("F1M20,10L30,10L30,40L20,40z");
var cross = Geometry.Parse("F1M20,10L20,10L30,10L30,20L40,20L40,30L30,30L30,40L20,40L20,30L10,30L10,20L20,20z");
var combined = new GeometryGroup(){ FillRule = FillRule.Nonzero };
combined.Children.Add(hBar);
combined.Children.Add(vBar);
var union = new CombinedGeometry(GeometryCombineMode.Union, HBar.Geometry, VBar.Geometry);
Console.WriteLine($"hBar : {hBar}");
Console.WriteLine($"vBar : {vBar}");
Console.WriteLine($"cross : {cross}");
Console.WriteLine($"combined : {combined}");
Console.WriteLine($"union : {union}");
图片如下:
代码输出如下:
hBar : F1M10,20L40,20 40,30 10,30z
vBar : F1M20,10L30,10 30,40 20,40z
cross : F1M20,10L20,10 30,10 30,20 40,20 40,30 30,30 30,40 20,40 20,30 10,30 10,20 20,20z
combined : System.Windows.Media.GeometryGroup
union : System.Windows.Media.CombinedGeometry
我希望得到 CombinedGeometry
和 GeometryGroup
对象的路径标记语法。例如,特别是在 'union' 的情况下,我希望找回类似于 cross
条目的内容。
(* 注意:我不关心顶点的顺序或绘图方向,只要它显示为相同 shape/path。)
这是有关 Path Markup Syntax 的 Microsoft 页面。这是我要获取的格式。
这可能吗?
也许我没有抓住要点,但恢复路径非常简单...
foreach(var child in combined.Children)
{
Console.WriteLine($" child of combined = {child.ToString()}");
}
Console.WriteLine($" union.Geometry1 = {union.Geometry1}");
Console.WriteLine($" union.Geometry2 = {union.Geometry2}");
产生...
child of combined = F1M10,20L40,20 40,30 10,30z
child of combined = F1M20,10L30,10 30,40 20,40z
union.Geometry1 = F1M10,20L40,20 40,30 10,30z
union.Geometry2 = F1M20,10L30,10 30,40 20,40z
是的,只是展平几何体。但是请注意,此 returns 是几何体的多边形表示。
union.GetFlattenedPathGeometry().ToString()
为了保持原始曲线,为此似乎有许多内置变化,我将它们留在这里供以后的读者使用。
PathGeometry.CreateFromGeometry(combined).ToString()
PathGeometry.CreateFromGeometry(union).ToString()
Geometry.Combine(hBar, vBar, GeometryCombineMode.Union, null).ToString()