Getting actual path of PathGeometry

2019-08-01 02:00发布

Is there a way to get the actual path of a PathGeometry in WPF? I've looked at RenderedGeometry, but it doesn't appear to provide anything other than what I put in.

For example, here's my XAML:

<Path x:Name="right" Canvas.Left="10" Canvas.Top="10" StrokeThickness="3" 
      Stroke="Black" StrokeEndLineCap="Round" StrokeStartLineCap="Round" 
      StrokeLineJoin="Miter" Data="M0,9L4.5,0L9,9 "/>`

This produces:
enter image description here

Does WPF provide any function natively or is there way to get the traced outline of this shape in path data?

I've also tried Petzold's attempt at something similar to this here, but it simply doesn't work.

1条回答
放荡不羁爱自由
2楼-- · 2019-08-01 02:14

Use GetWidenedPathGeometry with a Pen that applies all relevant stroke-related properties from the source Path.

var pen = new Pen
{
    Thickness = right.StrokeThickness,
    StartLineCap = right.StrokeStartLineCap,
    EndLineCap = right.StrokeEndLineCap,
    LineJoin = right.StrokeLineJoin,
    MiterLimit = right.StrokeMiterLimit
};

var geometry = right.Data.GetWidenedPathGeometry(pen);
查看更多
登录 后发表回答