3

I am trying to use text recognition with the WPF InkCanvas control on a Windows 8.1 computer with .Net 4.5.

Note: **WPF InkCanvas control Windows 8.1 **, not Windows Forms, nor Windows Apps!

According to the help it should be quite easy:

MSDN: Handwriting Recognition

However when I get to this paragraph I get stuck.

Add a reference to the WPF Ink Analysis assemblies, IAWinFX.dll, IACore.dll, and IALoader.dll, which can be found in \Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7. Replace the contents of the code behind file with the following code.

I do not have these files on my computer. I tried on my Windows 7 Pro PC and can still not find them.

From searching stackoverflow and elsewhere it seems that other people have had similar issues, and there also seem to be several different versions of inking/handwriting recognition available. For instance it appears that putting it in a Windows 8 Store App should be quite easy. But my question is specifically about a WPF program with .NET 4.5 as per the MSDN documentation!

The Gardener
  • 121
  • 1
  • 7

2 Answers2

4

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

Tam Bui
  • 2,940
  • 2
  • 18
  • 27
  • 1
    The MSDN link in step 2 has changed slightly to: https://msdn.microsoft.com/en-us/library/vstudio/ms754080(v=VS.100).aspx – eshan Aug 23 '15 at 23:01
  • 2
    This works great using Windows 10 on a Surface Pro with .NET 4.5.2. Thanks. Just to let everyone know I did a search for Microsoft.Ink.dll on my system and found it in Program Files\Common Files\Microsoft Shared\Ink. Didn't have to install anything, just referenced the file and used the buttonClick code. – digthewells Jun 27 '16 at 15:53
0

Please try the below sample for windows 8. https://code.msdn.microsoft.com/windowsapps/InkPen-sample-in-CSharp-189ce853/sourcecode?fileId=60841&pathId=233613099

Ayyappan Subramanian
  • 5,348
  • 1
  • 22
  • 44
  • Thanks. The system requirements are Windows XP. Does it work on Windows 8 - I can try it out I suppose! But it is 10 years old - is this the latest technology that MS have, or is it just acting as an interface to the more modern recognisers on my computer? – The Gardener Dec 16 '14 at 15:27
  • Please try the link.https://code.msdn.microsoft.com/windowsapps/InkPen-sample-in-CSharp-189ce853/sourcecode?fileId=60841&pathId=233613099 – Ayyappan Subramanian Dec 16 '14 at 17:51
  • 1
    Okay - your first was just link to the Tablet SDK from 2004. It does install and work on Windows 8, and it includes a working example using Windows Forms. This is not the same as WPF. The second example is for a Windows Store App. Both of these links are easily found by a cursory search of MSDN. I get the impression that you haven't actually tried this and are trying to ape lmgtfy dot com – The Gardener Dec 17 '14 at 09:27