WPF Handwriting .NET 4.5 Windows 8: Missing IAWinFX.dll and others

末鹿安然 提交于 2019-12-01 08:05:54

I just went down the exact same path as you, and I have a solution. The MSDN Handwriting Recognition link that you stated simply doesn't work, and it is because it relies on the InkAnalyzer class which is only available if you install the Tablet PC v1.7 SDK on an XP machine (it won't install on Windows 8).

Having said that, installing the Tablet PC v1.7 SDK does install the Microsoft.Ink.dll, which you can use to perform handwriting recognition. The only downside is that you will have to take your WPF InkCanvas strokes and save them into the Microsoft.Ink.InkCollector strokes.

The solution is as follows:

1) Install the Windows XP Tablet PC SDK v1.7

2) Follow all of the same source code as outlined by the MSDN Handwriting Recognition guidance, except for the buttonClick implementation.

3) Add a reference to your WPF Application by browsing and selecting this dll: C:\Program Files (x86)\Microsoft Tablet PC Platform SDK\Include\Microsoft.Ink.dll

4) Add a 'using Microsoft.Ink' statement to the top of your MainWindow.xaml.cs file, and then add the following code to your buttonClick method:

    private void buttonClick(object sender, RoutedEventArgs e)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            theInkCanvas.Strokes.Save(ms);
            var myInkCollector = new InkCollector();
            var ink = new Ink();
            ink.Load(ms.ToArray());

            using (RecognizerContext myRecoContext = new RecognizerContext())
            {
                RecognitionStatus status;
                myRecoContext.Strokes = ink.Strokes;
                var recoResult = myRecoContext.Recognize(out status);

                if (status == RecognitionStatus.NoError)
                {
                    textBox1.Text = recoResult.TopString;
                    theInkCanvas.Strokes.Clear();
                }
                else
                {
                    MessageBox.Show("ERROR: " + status.ToString());
                }
            }
        }
    }

That's it!!! One important note that I'd like to add. If you are trying to do handwriting recognition on Windows 10 or later, and you're not hindered by having to write a desktop WPF app, I highly recommend the usage of their DirectInk technology. I've tested it on a Windows 10 RC and it is much much easier to use. Unfortunately, it only works with their Universal Apps (Metro) and not Desktop Apps (WPF).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!