GestureRecognizer.Recognize(StrokeCollection) 方法

定义

在指定的 StrokeCollection 中寻找笔势。

public:
 System::Collections::ObjectModel::ReadOnlyCollection<System::Windows::Ink::GestureRecognitionResult ^> ^ Recognize(System::Windows::Ink::StrokeCollection ^ strokes);
[System.Security.SecurityCritical]
public System.Collections.ObjectModel.ReadOnlyCollection<System.Windows.Ink.GestureRecognitionResult> Recognize (System.Windows.Ink.StrokeCollection strokes);
public System.Collections.ObjectModel.ReadOnlyCollection<System.Windows.Ink.GestureRecognitionResult> Recognize (System.Windows.Ink.StrokeCollection strokes);
[<System.Security.SecurityCritical>]
member this.Recognize : System.Windows.Ink.StrokeCollection -> System.Collections.ObjectModel.ReadOnlyCollection<System.Windows.Ink.GestureRecognitionResult>
member this.Recognize : System.Windows.Ink.StrokeCollection -> System.Collections.ObjectModel.ReadOnlyCollection<System.Windows.Ink.GestureRecognitionResult>
Public Function Recognize (strokes As StrokeCollection) As ReadOnlyCollection(Of GestureRecognitionResult)

参数

strokes
StrokeCollection

要在其中搜索笔势的 StrokeCollection

返回

ReadOnlyCollection<GestureRecognitionResult>

GestureRecognitionResult 类型的数组,该数组包含 GestureRecognizer 所识别的应用程序笔势。

属性

示例

以下示例演示如何确定某个 Stroke 手势是否为 ScratchOut 手势。

private bool InterpretScratchoutGesture(Stroke stroke)
{
    // Attempt to instantiate a recognizer for scratchout gestures.
    ApplicationGesture[] gestures = { ApplicationGesture.ScratchOut };
    GestureRecognizer recognizer = new GestureRecognizer(gestures);

    if (!recognizer.IsRecognizerAvailable)
        return false;

    // Determine if the stroke was a scratchout gesture.
    StrokeCollection gestureStrokes = new StrokeCollection();
    gestureStrokes.Add(stroke);

    ReadOnlyCollection<GestureRecognitionResult> results = recognizer.Recognize(gestureStrokes);

    if (results.Count == 0)
        return false;

    // Results are returned sorted in order strongest-to-weakest; 
    // we need only analyze the first (strongest) result.
    if (results[0].ApplicationGesture == ApplicationGesture.ScratchOut &&
          results[0].RecognitionConfidence == RecognitionConfidence.Strong)
    {
        // Use the scratchout stroke to perform hit-testing and 
        // erase existing strokes, as necessary.
        return true;
    }
    else
    {
        // Not a gesture: display the stroke normally.
        return false;
    }
}
Private Function InterpretScratchoutGesture(ByVal stroke As Stroke) As Boolean
    ' Attempt to instantiate a recognizer for scratchout gestures.
    Dim gestures() As ApplicationGesture = {ApplicationGesture.ScratchOut}

    Dim recognizer As New GestureRecognizer(gestures)

    If Not recognizer.IsRecognizerAvailable Then
        Return False
    End If

    ' Determine if the stroke was a scratchout gesture.
    Dim gestureStrokes As StrokeCollection = New StrokeCollection()
    gestureStrokes.Add(stroke)

    Dim results As ReadOnlyCollection(Of GestureRecognitionResult)
    results = recognizer.Recognize(gestureStrokes)

    If results.Count = 0 Then
        Return False
    End If

    ' Results are returned sorted in order strongest-to-weakest; 
    ' we need only analyze the first (strongest) result.
    If (results(0).ApplicationGesture = ApplicationGesture.ScratchOut) Then

        ' Use the scratchout stroke to perform hit-testing and 
        ' erase existing strokes, as necessary.
        Return True
    Else
        ' Not a gesture: display the stroke normally.
        Return False
    End If
End Function

注解

方法返回的 Recognize 数组按 GestureRecognitionResult.RecognitionConfidence 属性排序。 例如, Recognize 可以返回具有以下 GestureRecognitionResult 值的数组:

索引 ApplicationGesture RecognitionConfidence
0 Check Strong
1 NoGesture Intermediate
2 Curlicue Poor
3 DoubleCurlicue Poor

这意味着, GestureRecognizer 识别出,这是一个复选标记的可能性很大 Stroke ,相对可能 Stroke 不是手势,根本不可能是 Stroke 卷曲或双卷曲。

备注

该方法Recognize可以返回具有高于其他应用程序手势的RecognitionConfidence数组NoGesture。 这意味着,它更有可能 Stroke 不是手势,而不是具有较低 RecognitionConfidence手势的手势。

适用于