1

I am trying to convert some scanned handwritten material into InkCanvas for handwriting recognition using InkAnalyser. I already have my handwriting material available in XAML.

I have this path (boundary shape of alphabet t) saved in a .XAML file physically:

<Path xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  Fill="#ff231f20" Data="F1 M 
7.931,2.750 L 7.931,12.267 L 0.000,12.267 L 0.000,19.351 L 7.931,19.351 L 7.931,47.268 C 
7.931,53.295 8.988,57.842 11.526,60.697 C 13.747,63.129 17.236,64.609 21.572,64.609 C 
25.167,64.609 28.022,63.975 29.820,63.340 L 29.396,56.256 C 28.022,56.679 26.542,56.890 
24.004,56.890 C 18.822,56.890 17.025,53.295 17.025,46.950 L 17.025,19.351 L 30.349,19.351 
L 30.349,12.267 L 17.025,12.267 L 17.025,0.000 L 7.931,2.750 Z"/>

I read XAML of the Path and load it into Path object from MemoryStream object ms like this:

Path myPath = (System.Windows.Shapes.Path)XamlReader.Load(ms);

I have an InkCanvas named V. I would like to programmatically create stroke data out of myPath object and add it into InkCanvas.

Note: I don't want to add myPath as a UI element into InkCanvas V's Children.

I tried this: http://code.msdn.microsoft.com/windowsdesktop/A-Coordinate-supported-03e4f1b7 is an MSDN article describing how to draw coordinate axis into an InkCanvas. He is explaining the drawing the axis part into DrawingContext object.

But he doesn't explain how to actually load those drawings onto a real InkCanvas object through this DrawingContext object. I need help exactly there.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • The drawing context is about the rendering of the control, it has nothing to do with the functionality and the strokes of the InkCanvas. – H.B. Jan 02 '12 at 22:23
  • I covered that part in my question. I am aware of it. –  Jan 02 '12 at 22:31

1 Answers1

1

Get all the points from the path, create StylusPoints from their coordinates. Create a StylusPointCollection from those StylusPoints and use the respective Stroke constructor to make a stroke, this Stroke then can be added to the Strokes of the canvas.

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • my path contains bezier elements. the only way is to enumerate the set of all points contained within the boundary and add them to StylusPointCollection u say? –  Jan 02 '12 at 22:32
  • @Pandey: Strokes only consist of points with pressure values, if you have bezier elements you can approximate those with intermediate points. – H.B. Jan 02 '12 at 22:44