更新:2007 年 11 月
本节讨论了与 WPF 平台中数字墨迹有关的识别的基本知识。
识别解决方案
下面的示例演示如何使用 InkAnalyzer 识别墨迹。
![]() |
---|
此示例要求在系统上安装手写识别器。 |
在 Visual Studio 2005 中创建一个名为 InkRecognition 的新 WPF 应用程序项目。用下列 XAML 代码替换 Window1.xaml 文件的内容。此代码将呈现应用程序的用户界面。
<Window x:Class="InkRecognition.Window1"
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
Title="InkRecognition"
>
<Canvas Name="theRootCanvas">
<Border
Background="White"
BorderBrush="Black"
BorderThickness="2"
Height="300"
Width="300"
Canvas.Top="10"
Canvas.Left="10">
<InkCanvas Name="theInkCanvas"></InkCanvas>
</Border>
<TextBox Name="textBox1"
Height="25"
Width="225"
Canvas.Top="325"
Canvas.Left="10"></TextBox>
<Button
Height="25"
Width="75"
Canvas.Top="325"
Canvas.Left="235"
Click="buttonClick">Recognize</Button>
</Canvas>
</Window>
添加对 WPF 墨迹分析程序集、IAWinFX.dll、IACore.dll 和 IALoader.dll(这些内容可以在 \Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7 中找到)的引用。用下列代码替换代码隐藏文件的内容。
Imports System.Windows
Imports System.Windows.Ink
'/ <summary>
'/ Interaction logic for Window1.xaml
'/ </summary>
Namespace InkRecognition
Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
End Sub 'New
' Recognizes handwriting by using RecognizerContext
Private Sub buttonClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim theInkAnalyzer As New InkAnalyzer()
theInkAnalyzer.AddStrokes(theInkCanvas.Strokes)
Dim status As AnalysisStatus = theInkAnalyzer.Analyze()
If status.Successful Then
textBox1.Text = theInkAnalyzer.GetRecognizedString()
Else
MessageBox.Show("Recognition Failed")
End If
End Sub 'buttonClick
End Class 'Window1
End Namespace
using System.Windows;
using System.Windows.Ink;
namespace InkRecognition
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
// Recognizes handwriting by using RecognizerContext
private void buttonClick(object sender, RoutedEventArgs e)
{
InkAnalyzer theInkAnalyzer = new InkAnalyzer();
theInkAnalyzer.AddStrokes(theInkCanvas.Strokes);
AnalysisStatus status = theInkAnalyzer.Analyze();
if (status.Successful)
{
textBox1.Text = theInkAnalyzer.GetRecognizedString();
}
else
{
MessageBox.Show("Recognition Failed");
}
}
}
}