如何绘制在WPF的平滑曲线? [英] How to draw a smooth curved line in WPF?
问题描述
我有三个已知位置,目前我开车两行,像这样:
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);
下面的结果:
所以,你可以看到,这几乎是我想要的,不过,我希望它是更平滑,只是一点点。
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.
现在我正在寻找什么办法可以设置三个点,设置一些光滑/弯曲的水平中点,然后画一条线用纯色就可以了。就像我怎么可以在Photoshop做到这一点:
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:
或者至少得到一个类似一种平滑的。
Or at least get a similar kind of smoothness.
推荐答案
我认为你正在寻找花键
http://msdn.microsoft.com/en-us/library/ 554h284b.aspx
加布是正确的是形式
在WPF,你可以尝试PolyBezierSegment但它需要4分。可能你可以把三个分和1个多塑造它。
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.
<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>
这将产生以下曲线
这篇关于如何绘制在WPF的平滑曲线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!