开发者

Transferring set of points to Bezier curve

In my WPF application I'm working on a drawing mechanism to make annotations on top of images. For now I have functionality to draw paths where my drawn path will consist of the collected points from the drawing. More closely I'm adding StylusPoints to an InkPresenter as I collect them through the MouseMoved event. The InkPresenter is set as child to a Canvas, which then is what will hold 开发者_JAVA百科the drawings. I could also draw a LineSegment in a Path if that's any different?

My problem with this drawing is that it won't be smooth. Therefore I'd like the resulting curve to be represented as a Bezier curve. This is a technique used e.g. in Adobe Illustrator. Now; is there a way to handle this? To first build a collection of points that represents the bumpy curve drawn, and then transform this to a Bezier curve which resembles the drawn curve?


If you want to fit a curve to a set of points, think spline (of which Bezier is a subset).

Here is a PDF about how to fit a Bezier to four points, easily extended to n. This came from Don Lancaster's guru's lair, which has a great set of tutorials on Beziers.


Charles Petzold has a class CanonicalSpline in the sample code for his Line Chart With Data Templates article in MSDN Magazine.

Sample Code

The key method of the class creates a PathGeometry from a set of points.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜