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
Please try the below sample for windows 8. https://code.msdn.microsoft.com/windowsapps/InkPen-sample-in-CSharp-189ce853/sourcecode?fileId=60841&pathId=233613099
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).