views:

273

answers:

2

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 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?

+1  A: 

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.

Doug Ferguson
+1  A: 

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.

plinth