Tablet PC: Getting started with InkAnalysis in WPF
So far, I’ve highlighted working with the new InkAnalysis API (common API that exposes both ink parsing and handwriting recognition) using the COM and Winforms APIs. Now that WPF is public, let’s take a look at how you can incorporate InkAnalysis with your WPF application. We’ll take a look at adding InkAnalysis functionality to the InkCanvas control.
Getting started:
Here’s what you’ll need to get your machine ready for WPF InkAnalysis development:
1. Install VS.NET 2005 (Express or full)
2. Install the .NET Framework 3.0 runtime (This installs WPF)
3. Install the Windows Vista SDK (This installs the tablet pc platform componenets and InkAnalysis WPF assembly- IAWinFx.dll)
4. Install the Visual Studio extensions for WPF
5. If you’re on a non-Tablet PC platform, install the recognizer pack
6. Follow the instructions (step 4 only) HERE
Create your project:
Here’s how to get your project created in Visual Studio: (Depending on your defaults, this may look different)
1. New ProjectàOther LanguagesàVisual C# àNET Framework 3.0àWindows Application (3.0)
2. From the toolbox, drag an InkCanvas onto the window in the designer
3. Run the project, verify that you can collect ink
4. Add a reference to IAWinfx from %ProgramFiles%\Reference Assemblies\Microsoft\Tablet PC\v1.7
5. Add a “using System.Windows.Ink” statement in your *.xaml.cs file
Hook up InkAnalysis functionality:
1. Add a button with text “Analyze” to the window
2. Add a handler for the button’s click event
3. Perform analysis on the ink in the click handler, display the result (See example code below)
Screenshot of application running:
Example code:
// Call Analyze() if we have strokes and display // the result to the user void buttonAnalyze_Click(object sender, RoutedEventArgs e) { if (this.inkCanvas1.Strokes.Count == 0) { return; // Do nothing... }
// Setup the InkAnalyzer InkAnalyzer analyzer = new InkAnalyzer(); analyzer.AddStrokes(this.inkCanvas1.Strokes); // Perform synchronous analysis AnalysisStatus status = analyzer.Analyze(); // Display the result string message = ""; if (status.Successful == true) { message = analyzer.GetRecognizedString(); } else { message = "Analyze failed"; } MessageBox.Show(message, "Basic WPF InkAnalysis Application"); // Clean up analyzer.Dispose(); // Required to free unmanaged resources } |
There you have it! Basic WPF InkAnalysis up and going. This shows you how to get the plumbing hooked up in WPF for InkAnalysis. The InkAnalyzer is used in almost the same way as Winforms, so if you read my other blog posts, most of them will apply to WPF.
See Ya,
Gavin
Comments
- Anonymous
December 08, 2006
PingBack from http://www.gottabemobile.com/GettingStartedWithInkAnalysisInWPF.aspx