共用方式為


手寫辨識

更新:2007 年 11 月

本章節討論辨識 WPF 平台數位筆墨相關的基本原理。

辨識方案

下列範例顯示如何使用 InkAnalyzer 辨識筆墨。

注意事項:

這個範例需要在系統上安裝手寫辨識器。

在 Visual Studio 2005 中建立名為 InkRecognition 的新 WPF 應用程式。將 Window1.xaml 檔案的內容取代成下列 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 Ink Analysis 組件 IAWinFX.dll、IACore.dll 和 IALoader.dl 的參考,這些組件可以在 \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");
            }
        }

    }
}

請參閱

參考

InkAnalyzer

AnalysisStatus

InkCanvas