필기 인식
이 섹션에서는 WPF 플랫폼의 디지털 링크에 관련되므로 인식의 기본 개념을 설명합니다.
인식 솔루션
다음 예에서는 Microsoft.Ink.InkCollector 클래스를 사용하여 잉크를 인식하는 방법을 보여줍니다.
참고
이 샘플에서는 필기 인식기를 시스템에 설치해야 합니다.
InkRecognition라는 새 WPF 애플리케이션 프로젝트를 Visual Studio에 만듭니다. Window1.xaml 파일의 콘텐츠를 다음 XAML 코드로 바꿉니다. 이 코드는 애플리케이션의 사용자 인터페이스를 렌더링합니다.
<Window x:Class="InkRecognition.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://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>
<Button x:Name="btnClear" Content="Clear Canvas" Canvas.Left="10" Canvas.Top="367" Width="75" Click="btnClear_Click"/>
</Canvas>
</Window>
\Program Files\Common Files\Microsoft Shared\Ink에 있는 Microsoft Ink 어셈블리, Microsoft.Ink.dll에 참조를 추가합니다. 파일의 기반이 되는 코드의 콘텐츠를 다음 코드로 바꿉니다.
using System.Windows;
using Microsoft.Ink;
using System.IO;
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)
{
using (MemoryStream ms = new MemoryStream())
{
theInkCanvas.Strokes.Save(ms);
var myInkCollector = new InkCollector();
var ink = new Ink();
ink.Load(ms.ToArray());
using (RecognizerContext context = new RecognizerContext())
{
if (ink.Strokes.Count > 0)
{
context.Strokes = ink.Strokes;
RecognitionStatus status;
var result = context.Recognize(out status);
if (status == RecognitionStatus.NoError)
textBox1.Text = result.TopString;
else
MessageBox.Show("Recognition failed");
}
else
{
MessageBox.Show("No stroke detected");
}
}
}
}
private void btnClear_Click(object sender, RoutedEventArgs e) {
theInkCanvas.Strokes.Clear();
}
}
}
Imports System.Windows
Imports Microsoft.Ink
Imports System.IO
'/ <summary>
'/ Interaction logic for Window1.xaml
'/ </summary>
Namespace InkRecognition
Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
' Recognizes handwriting by using RecognizerContext
Private Sub buttonClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
Using ms As New MemoryStream()
theInkCanvas.Strokes.Save(ms)
Dim myInkCollector As InkCollector = New InkCollector()
Dim ink As Ink = New Ink()
ink.Load(ms.ToArray())
Using context As New RecognizerContext()
If ink.Strokes.Count > 0 Then
context.Strokes = ink.Strokes
Dim status As RecognitionStatus
Dim result As RecognitionResult = context.Recognize(status)
If status = RecognitionStatus.NoError Then
textBox1.Text = result.TopString
Else
MessageBox.Show("Recognition failed")
End If
Else
MessageBox.Show("No stroke detected")
End If
End Using
End Using
End Sub
Private Sub btnClear_Click(sender As Object, e As RoutedEventArgs)
theInkCanvas.Strokes.Clear()
End Sub
End Class
End Namespace
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET Desktop feedback
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기