RecognizerContext.BackgroundRecognize 메서드
업데이트: 2007년 11월
Recognizer 개체에서 연결된 Strokes 컬렉션을 인식하게 하고, 인식이 완료되면 Recognition 이벤트를 발생시킵니다.
네임스페이스: Microsoft.Ink
어셈블리: Microsoft.Ink(Microsoft.Ink.dll)
구문
‘선언
Public Sub BackgroundRecognize
‘사용 방법
Dim instance As RecognizerContext
instance.BackgroundRecognize()
public void BackgroundRecognize()
public:
void BackgroundRecognize()
public void BackgroundRecognize()
public function BackgroundRecognize()
설명
이 메서드는 잉크 인식이 비동기 방식으로 수행되도록 지정합니다. 잉크를 동기 방식으로 인식하려면 RecognizerContext.Recognize 메서드를 호출합니다.
이 메서드는 최적 결과 문자열만을 인식하며 RecognitionAlternate 개체를 만들지 않습니다. 사용 가능한 대체 항목 목록을 만드는 인식을 수행하려면 BackgroundRecognizeWithAlternates 메서드를 호출합니다.
인식기가 아무런 항목도 인식하지 않으면 Recognition 이벤트는 발생하지 않습니다.
예제
이 예제에서는 InkOverlay 개체에 작성되는 각 스트로크를 자동으로 인식하고 인식 결과를 표시합니다.
응용 프로그램 시작 중에 RecognizerContext 개체가 인스턴스화되고 이벤트 처리기가 할당됩니다.
' create a new RecognizerContext object
' the object's Strokes property is initialized to null
mRecognizerContext = New RecognizerContext()
' assign the Strokes property by creating a fresh Strokes collection
mRecognizerContext.Strokes = mInkOverlay.Ink.CreateStrokes()
' subscribe to the Strokes event. It is during this event
' that we can add strokes to the RecognizerContext
AddHandler mInkOverlay.Stroke, New InkCollectorStrokeEventHandler(AddressOf mInkOverlay_Stroke2)
' subscribe to the the Recognition event.
' This event is fired when background recognition is complete,
' and recognition results (without alternates) are available
AddHandler mRecognizerContext.Recognition, _
New RecognizerContextRecognitionEventHandler(AddressOf mRecognizerContext_Recognition)
// create a new RecognizerContext object
// the object's Strokes property is initialized to null
mRecognizerContext = new RecognizerContext();
// assign the Strokes property by creating a fresh Strokes collection
mRecognizerContext.Strokes = mInkOverlay.Ink.CreateStrokes();
// subscribe to the Strokes event. It is during this event
// that we can add strokes to the RecognizerContext
mInkOverlay.Stroke += new InkCollectorStrokeEventHandler(mInkOverlay_Stroke2);
// subscribe to the the Recognition event.
// This event is fired when background recognition is complete,
// and recognition results (without alternates) are available
mRecognizerContext.Recognition +=
new RecognizerContextRecognitionEventHandler(mRecognizerContext_Recognition);
사용자가 스트로크를 완성하여 Stroke 이벤트가 발생하면 새로 만들어진 스트로크가 RecognizerContext 개체의 Strokes 컬렉션에 추가되고 BackgroundRecognize 메서드가 호출됩니다.
Private Sub mInkOverlay_Stroke2(ByVal sender As Object, ByVal e As InkCollectorStrokeEventArgs)
' in case background recognition is still occurring, stop it
mRecognizerContext.StopBackgroundRecognition()
' add the stroke, and start recognition
mRecognizerContext.Strokes.Add(e.Stroke)
mRecognizerContext.BackgroundRecognize()
End Sub
private void mInkOverlay_Stroke2(object sender, InkCollectorStrokeEventArgs e)
{
// in case background recognition is still occurring, stop it
mRecognizerContext.StopBackgroundRecognition();
// add the stroke, and start recognition
mRecognizerContext.Strokes.Add(e.Stroke);
mRecognizerContext.BackgroundRecognize();
}
백그라운드 인식이 완료되면 Recognition 이벤트가 발생합니다. 이 이벤트를 처리하는 동안 인식 결과가 목록 상자에 배치됩니다.
' event fires when recognition results (without alternates) are ready
Private Sub mRecognizerContext_Recognition(ByVal sender As Object, _
ByVal e As RecognizerContextRecognitionEventArgs)
' when updating a control, must use Invoke() since controls are
' not thread safe and recognition occurs on a different thread
If Me.InvokeRequired Then
' recursively call this method via Invoke()
Me.Invoke( _
New RecognizerContextRecognitionEventHandler(AddressOf mRecognizerContext_Recognition), _
New Object() {sender, e} _
)
Return
End If
If RecognitionStatus.NoError = e.RecognitionStatus Then
listBoxRecognitionResults.Items.Add(e.Text)
End If
End Sub
// event fires when recognition results (without alternates) are ready
private void mRecognizerContext_Recognition(object sender, RecognizerContextRecognitionEventArgs e)
{
// when updating a control, must use Invoke() since controls are
// not thread safe and recognition occurs on a different thread
if (this.InvokeRequired)
{
// recursively call this method via Invoke()
this.Invoke(
new RecognizerContextRecognitionEventHandler(mRecognizerContext_Recognition),
new object[] { sender, e }
);
return;
}
if (RecognitionStatus.NoError == e.RecognitionStatus)
{
listBoxRecognitionResults.Items.Add(e.Text);
}
}
플랫폼
Windows Vista
.NET Framework 및 .NET Compact Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
3.0에서 지원