Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 转换路径&;笔划宽度到几何体_C#_Wpf_Pathgeometry - Fatal编程技术网

C# 转换路径&;笔划宽度到几何体

C# 转换路径&;笔划宽度到几何体,c#,wpf,pathgeometry,C#,Wpf,Pathgeometry,我有一段代码,它获取许多点并创建多条线段来构建路径 System.Windows.Shapes.Path pathSegment = new System.Windows.Shapes.Path(); PathFigure pathFig = new PathFigure(); PathGeometry pathGeo = new PathGeometry(); pathFig.StartPoint = new Point(pointData[0].X, pointData[0].Y); for

我有一段代码,它获取许多点并创建多条线段来构建路径

System.Windows.Shapes.Path pathSegment = new System.Windows.Shapes.Path();
PathFigure pathFig = new PathFigure();
PathGeometry pathGeo = new PathGeometry();
pathFig.StartPoint = new Point(pointData[0].X, pointData[0].Y);
for (int loop = 1; loop < pointData.Count; loop++)
{
    LineSegment ls = new LineSegment();        
    ls.Point = new Point(pointData[loop].X, pointData[loop].Y);
    pathFig.Segments.Add(ls);
}

pathGeo.Figures.Add(pathFig);
pathSegment.Data = pathGeo;
pathSegment.Stroke = brush;
pathSegment.StrokeThickness = 22;
System.Windows.Shapes.Path路径段=新的System.Windows.Shapes.Path();
PathFigure pathFig=新的PathFigure();
PathGeometry pathGeo=新的PathGeometry();
pathFig.StartPoint=新点(点数据[0].X,点数据[0].Y);
for(int loop=1;loop
这将创建宽度为22px(大致)的线条。现在,如果您查看此项的实际数据,您只能看到LineSegment元素,它本质上为您提供了这样的输出,其中实际线条为黑色,实际显示的线条为灰色(请原谅狡猾的mspaint草图):

现在,我想对几何体执行StrokeContains,以查看指定点是否位于上面的整个pathSegment(灰色区域)内。但它实际做的是对照线段(黑线)进行检查


有没有更好的方法来建立这条道路?或者有没有办法将pathSegment(包括StrokeWidth)转换为新路径?

如果在StrokeContains调用中使用正确的笔厚,应该可以:

Point point = ...
Pen pen = new Pen { Thickness = pathSegment.StrokeThickness };
bool contains = pathSegment.Data.StrokeContains(pen, point);
或者,您可以简单地在路径上执行命中测试:

bool contains = pathSegment.InputHitTest(point) != null;

谢谢,我在发布后不久就发现了StrokeContains,这是一种享受。我刚刚在与StrokeContains一起工作的同一代码上尝试了InAuthitTest,但由于某种原因,它从未检测到。