WPF手写识别

2017-04-04 19:38:11来源:CSDN作者:yue1241630499人点击

使用微软自带的识别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为InkCanvasMicrosoft.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());   }}

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台