Ejemplo n.º 1
0
        private void theInkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
        {
            var stroke = GetCombinedStore(this.theInkCanvas.Strokes);

            InkAnalyzer theInkAnalyzer = new InkAnalyzer();

            //theInkAnalyzer.AddStrokes(this.theInkCanvas.Strokes, 0x0804);
            //theInkAnalyzer.SetStrokesType(this.theInkCanvas.Strokes, StrokeType.Writing);

            theInkAnalyzer.AddStroke(stroke, 0x0804);
            theInkAnalyzer.SetStrokeType(stroke, StrokeType.Writing);
            AnalysisStatus status = theInkAnalyzer.Analyze();

            if (status.Successful)
            {
                List <StrokeWord> slist = new List <StrokeWord>();
                //textBox1.Text = theInkAnalyzer.GetRecognizedString();
                for (int i = 0; i < theInkAnalyzer.GetAlternates().Count; i++)
                {
                    StrokeWord sw = new StrokeWord();
                    sw.StrokeName = theInkAnalyzer.GetAlternates()[i].RecognizedString;
                    slist.Add(sw);
                }

                this.StrokeWordList = new List <StrokeWord>();
                this.StrokeWordList = slist;
            }
            else
            {
                MessageBox.Show("识别失败");
            }
        }
Ejemplo n.º 2
0
        private void theInkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
        {
            MemoryStream ms = new MemoryStream();

            theInkCanvas.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);

                    if (status == RecognitionStatus.NoError)
                    {
                        List <StrokeWord> slist = new List <StrokeWord>();
                        Microsoft.Ink.RecognitionAlternates als = recoResult.GetAlternatesFromSelection();
                        int resultCount = als.Count;
                        resultArray = new string[resultCount];
                        for (int i = 0; i < resultCount; i++)
                        {
                            StrokeWord sw = new StrokeWord();
                            sw.StrokeName = als[i].ToString();
                            slist.Add(sw);
                            //resultArray[i] = als[i].ToString();//多余
                        }

                        this.StrokeWordList = new List <StrokeWord>();
                        this.StrokeWordList = slist;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
                }
            }
        }