Getting actual path of PathGeometry

与世无争的帅哥 提交于 2019-12-11 07:07:33

问题


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:

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:


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);


来源:https://stackoverflow.com/questions/46384463/getting-actual-path-of-pathgeometry

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