<Grid>
<InkCanvas Name="inkCanvas"/>
<Button Content="识别" Click="Button_Click" VerticalAlignment="Bottom"/>
</Grid>
引用内库
Ink ink = new Ink();
private void Button_Click(object sender, RoutedEventArgs e)
{
using RecognizerContext recognizerContext = new RecognizerContext();
recognizerContext.Strokes = ink.CreateStrokes();
recognizerContext.Strokes.Add(CombineStroke());
RecognitionResult result = recognizerContext.Recognize(out RecognitionStatus status);
RecognitionAlternates als = result.GetAlternatesFromSelection();
List<string> strs = new List<string>();
for (int i = 0; i < als.Count; i++)
{
strs.Add(als[i].ToString());
}
}
private Stroke CombineStroke()
{
List<System.Drawing.Point> points = new List<System.Drawing.Point>();
foreach (var item in this.inkCanvas.Strokes)
{
points.AddRange(
item.StylusPoints.Select(p => new System.Drawing.Point((int)p.X, (int)p.Y)).ToList()
);
}
Stroke stroke = ink.CreateStroke(points.ToArray());
return stroke;
}