RecognizerContext.BackgroundRecognize 方法
使 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