C# 如何在 WPF 中绘制平滑的曲线?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10486906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to draw a smooth curved line in WPF?
提问by Tower
I have three known positions, and currently I am driving two lines like so:
我有三个已知职位,目前我正在驾驶两条线路:
Line line = new Line
{
StrokeThickness = 3,
Stroke = lineColor,
X1 = MyX,
Y1 = MyY,
X2 = MyX,
Y2 = MiddleY
};
Graph.Children.Add(line);
line = new Line
{
StrokeThickness = 3,
Stroke = lineColor,
X1 = MyX,
Y1 = MiddleY,
X2 = TargetX,
Y2 = TargetY
};
Graph.Children.Add(line);
Here's the result:
结果如下:


So, as you can see, this is almost what I want except that I want it to be more smoothed out, just a little bit.
所以,正如你所看到的,这几乎就是我想要的,只是我希望它更平滑,只是一点点。
Now I'm looking for any way I could set three points, set some smooth/curvy level to the middle point and then draw a line with a solid color on it. Much like how I can do this in Photoshop:
现在我正在寻找任何可以设置三个点的方法,在中间点设置一些平滑/弯曲的水平,然后在上面画一条纯色的线。就像我如何在 Photoshop 中做到这一点一样:


Or at least get a similar kind of smoothness.
或者至少获得类似的平滑度。
采纳答案by paparazzo
I think you are looking for splines
我想你正在寻找样条
http://msdn.microsoft.com/en-us/library/554h284b.aspx
http://msdn.microsoft.com/en-us/library/554h284b.aspx
Gabe is correct that is from Forms
Gabe 是正确的,来自 Forms
Under WPF you could try a PolyBezierSegment but it require 4 points. Possible you could put in three points and 1 more to shape it.
在 WPF 下,您可以尝试使用 PolyBezierSegment,但它需要 4 分。可能你可以放三个点和另外一个来塑造它。
<Canvas>
<Path Stroke="Black" StrokeThickness="10">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure StartPoint="100,80">
<PathFigure.Segments>
<PathSegmentCollection>
<PolyBezierSegment Points="90,200 140,200 160,200 180,200 430,190 430,280" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
</Canvas>
This results in the following curve
这导致以下曲线


回答by plinth
You want to use a PathFigure, specifically with a set of BezierSegments.
您想使用PathFigure,特别是一组BezierSegments。

