WPF手写识别

使用微软自带的识别dll.

IACore.dll\IALoader.dll\LAWinFX.dll\Microsoft.Ink.dll\Microsoft.InkAnalysis.dll

强调内容手写识别用到WPF中的InkCanvas控件,使用InkCanvas.Strokes来收集用户的手写笔迹。通过RecoginizerContext识别笔迹。

新建分析上下文环境,传如Ink中的笔迹,执行分析即可得到手写识别的结果,结果存放在RecognitionAlternates中,遍历该集合即可得到识别结果。具体代码如下:

MemoryStream ms = new MemoryStream();
canvas.Strokes.Save(ms);//canvas为InkCanvas
Microsoft.Ink.Ink ink = new Microsoft.Ink.Ink();
ink.Load(ms.ToArray());
string[] resultArray = null;//存放识别的结果
using (Microsoft.Ink.RecognizerContext myRecoContext = new Microsoft.Ink.RecognizerContext())
{
    Microsoft.Ink.RecognitionStatus status;//识别的结果状态,可用于判断是否识别成功
    Microsoft.Ink.RecognitionResult recoResult;
    myRecoContext.Strokes = ink.Strokes;
    try
    {
        recoResult = myRecoContext.Recognize(out status);
        Microsoft.Ink.RecognitionAlternates als = recoResult.GetAlternatesFromSelection();
        int resultCount = als.Count;
        resultArray = new string[resultCount];
        for (int i = 0; i < resultCount; i++)
        {
           resultArray[i] = als[i].ToString();
        }
    }
    catch (Exception ex)
   {
       System.Diagnostics.Debug.WriteLine(ex.ToString());
   }
}

猜你喜欢

转载自blog.csdn.net/yue1241630499/article/details/69061472