InkAnalyzerBase.AddStrokesToCustomRecognizer 方法

将多个笔画的笔画数据添加到自定义识别器节点。

命名空间:  System.Windows.Ink.AnalysisCore
程序集:  IACore(在 IACore.dll 中)

语法

声明
Public Function AddStrokesToCustomRecognizer ( _
    strokeIds As Integer(), _
    strokePacketCount As Integer(), _
    strokePacketData As Integer(), _
    strokePacketDescription As Guid(), _
    customRecognizer As ContextNodeBase _
) As ContextNodeBase
用法
Dim instance As InkAnalyzerBase
Dim strokeIds As Integer()
Dim strokePacketCount As Integer()
Dim strokePacketData As Integer()
Dim strokePacketDescription As Guid()
Dim customRecognizer As ContextNodeBase
Dim returnValue As ContextNodeBase

returnValue = instance.AddStrokesToCustomRecognizer(strokeIds, _
    strokePacketCount, strokePacketData, _
    strokePacketDescription, customRecognizer)
public ContextNodeBase AddStrokesToCustomRecognizer(
    int[] strokeIds,
    int[] strokePacketCount,
    int[] strokePacketData,
    Guid[] strokePacketDescription,
    ContextNodeBase customRecognizer
)
public:
ContextNodeBase^ AddStrokesToCustomRecognizer(
    array<int>^ strokeIds, 
    array<int>^ strokePacketCount, 
    array<int>^ strokePacketData, 
    array<Guid>^ strokePacketDescription, 
    ContextNodeBase^ customRecognizer
)
public ContextNodeBase AddStrokesToCustomRecognizer(
    int[] strokeIds,
    int[] strokePacketCount,
    int[] strokePacketData,
    Guid[] strokePacketDescription,
    ContextNodeBase customRecognizer
)
public function AddStrokesToCustomRecognizer(
    strokeIds : int[], 
    strokePacketCount : int[], 
    strokePacketData : int[], 
    strokePacketDescription : Guid[], 
    customRecognizer : ContextNodeBase
) : ContextNodeBase

参数

  • strokeIds
    类型:array<System.Int32[]
    包含笔画标识符的数组。
  • strokePacketCount
    类型:array<System.Int32[]
    包含每个笔画的数据包数目的数组。
  • strokePacketData
    类型:array<System.Int32[]
    包含笔画数据包数据的数组。
  • strokePacketDescription
    类型:array<System.Guid[]
    包含数据包属性标识符的数组。

返回值

类型:System.Windows.Ink.AnalysisCore.ContextNodeBase
墨迹分析器已将笔画添加到其中的上下文节点。

备注

InkAnalyzerBase 将笔画添加到一个 Type 属性值为 UnclassifiedInk() 的 ContextNodeBase

在分析过程中,墨迹分析器将活动输入线程的区域性标识符分配给笔画,并将笔画添加到墨迹识别器之下的第一个未分类墨迹节点。如果不存在任何未分类节点,则创建一个未分类节点。如果自定义识别器不支持该区域性标识符,则墨迹分析器继续分析并生成一个 AnalysisWarningBase 警告。此警告的 WarningCode 属性设置为 LanguageIdNotRespected 的 AnalysisWarningCode 值。

在对 AddStrokes 的单次调用中只能添加具有相同数据包描述的笔画。

此方法将 DirtyRegion 扩展为区域的当前值与所添加笔画的边界框的并集。

在以下情况下,InkAnalyzerBase 将引发异常。

示例

此示例定义一个方法,该方法将 Strokes 集合转换为数据包数据,然后将笔画添加到自定义识别器节点。该方法返回墨迹分析器向其添加笔画的 ContextNodeBase

''' <summary>
''' Adds a collection of strokes to a custom recognizer node.
''' </summary>
''' <param name="baseInkAnalyzer">The ink analyzer that contains the
''' custom recognizer node.</param>
''' <param name="theStrokes">The strokes to add.</param>
''' <param name="theCustomRecognizerNode">The custom recognizer node
''' to which to add the strokes.</param>
''' <returns>The node to which the analyzer added the strokes.</returns>
''' <remarks>
''' This method converts stroke data to packet data for example only.
''' The InkAnalyzerBase is used when your application is handling packet
''' data. If your application uses stroke data from an Ink object, then
''' you would use InkAnalyzer.
''' </remarks>
Public Overloads Shared Function MyAddStrokesToCustomRecognizer( _
ByVal baseInkAnalyzer As System.Windows.Ink.AnalysisCore.InkAnalyzerBase, _
ByVal theStrokes As Microsoft.Ink.Strokes, _
ByVal theCustomRecognizerNode As System.Windows.Ink.AnalysisCore.ContextNodeBase) _
As System.Windows.Ink.AnalysisCore.ContextNodeBase

    If Nothing Is baseInkAnalyzer Then
        Throw New ArgumentNullException("baseInkAnalyzer")
    End If

    If Nothing Is theStrokes Then
        Throw New ArgumentNullException("theStrokes")
    End If

    If 0 = theStrokes.Count Then
        Throw New ArgumentException("Empty strokes collection.")
    End If

    If System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.CustomRecognizer <> theCustomRecognizerNode.Type Then
        Throw New ArgumentException("The context node is not a custom recognizer node.", "theCustomRecognizer")
    End If

    If Nothing Is baseInkAnalyzer.FindNode(theCustomRecognizerNode.Id) Then
        Throw New ArgumentException("The custom recognizer node is not attached to the ink analyzer.")
    End If

    ' Only strokes that have the same packet description GUIDs
    ' can be added in one call to InkAnalyzerBase.AddStrokes.
    Dim thePacketDescription As Guid() = theStrokes(0).PacketDescription

    ' Accumulate the stroke data in collections.
    Dim theStrokeIdentifiers As New ArrayList()
    Dim thePacketCounts As New ArrayList()
    Dim thePacketData As New ArrayList()

    Dim aStroke As Microsoft.Ink.Stroke
    For Each aStroke In theStrokes
        If Not InkAnalyzerHelper.AreElementwiseEquivalent(aStroke.PacketDescription, thePacketDescription) Then
            Throw New ApplicationException("The strokes collection contains strokes with different packet descriptions.")
        End If

        ' Add the stroke data to the collections.
        theStrokeIdentifiers.Add(aStroke.Id)
        thePacketCounts.Add(aStroke.PacketCount)
        thePacketData.AddRange(aStroke.GetPacketData())
    Next aStroke

    ' Add the stroke data to the base layer ink analyzer.
    Dim result As System.Windows.Ink.AnalysisCore.ContextNodeBase = _
        baseInkAnalyzer.AddStrokesToCustomRecognizer( _
            DirectCast(theStrokeIdentifiers.ToArray(GetType(Integer)), Integer()), _
            DirectCast(thePacketCounts.ToArray(GetType(Integer)), Integer()), _
            DirectCast(thePacketData.ToArray(GetType(Integer)), Integer()), _
            thePacketDescription, _
            theCustomRecognizerNode)

    Return result

End Function 'AddStrokesToCustomRecognizer
/// <summary>
/// Adds a collection of strokes to a custom recognizer node.
/// </summary>
/// <param name="baseInkAnalyzer">The ink analyzer that contains the
/// custom recognizer node.</param>
/// <param name="theStrokes">The strokes to add.</param>
/// <param name="theCustomRecognizerNode">The custom recognizer node
/// to which to add the strokes.</param>
/// <returns>The node to which the analyzer added the strokes.</returns>
/// <remarks>
/// This method converts stroke data to packet data for example only.
/// The InkAnalyzerBase is used when your application is handling packet
/// data. If your application uses stroke data from an Ink object, then
/// you would use InkAnalyzer.
/// </remarks>
public static System.Windows.Ink.AnalysisCore.ContextNodeBase MyAddStrokesToCustomRecognizer(
    System.Windows.Ink.AnalysisCore.InkAnalyzerBase baseInkAnalyzer,
    Microsoft.Ink.Strokes theStrokes,
    System.Windows.Ink.AnalysisCore.ContextNodeBase theCustomRecognizerNode)
{
    if (null == baseInkAnalyzer)
    {
        throw new ArgumentNullException("baseInkAnalyzer");
    }

    if (null == theStrokes)
    {
        throw new ArgumentNullException("theStrokes");
    }

    if (0 == theStrokes.Count)
    {
        throw new ArgumentException("Empty strokes collection.");
    }

    if (System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.CustomRecognizer
        != theCustomRecognizerNode.Type)
    {
        throw new ArgumentException(
            "The context node is not a custom recognizer node.",
            "theCustomRecognizer");
    }

    if (null == baseInkAnalyzer.FindNode(theCustomRecognizerNode.Id))
    {
        throw new ArgumentException(
            "The custom recognizer node is not attached to the ink analyzer.");
    }

    // Only strokes that have the same packet description GUIDs
    // can be added in one call to InkAnalyzerBase.AddStrokes.
    Guid[] thePacketDescription = theStrokes[0].PacketDescription;

    // Accumulate the stroke data in collections.
    ArrayList theStrokeIdentifiers = new ArrayList();
    ArrayList thePacketCounts = new ArrayList();
    ArrayList thePacketData = new ArrayList();

    foreach (Microsoft.Ink.Stroke aStroke in theStrokes)
    {
        if (!InkAnalyzerHelper.AreElementwiseEquivalent(
            aStroke.PacketDescription, thePacketDescription))
        {
            throw new ApplicationException(
                "The strokes collection contains strokes with different packet descriptions.");
        }

        // Add the stroke data to the collections.
        theStrokeIdentifiers.Add(aStroke.Id);
        thePacketCounts.Add(aStroke.PacketCount);
        thePacketData.AddRange(aStroke.GetPacketData());
    }

    // Add the stroke data to the base layer ink analyzer.
    System.Windows.Ink.AnalysisCore.ContextNodeBase result =
        baseInkAnalyzer.AddStrokesToCustomRecognizer(
            theStrokeIdentifiers.ToArray(typeof(int)) as int[],
            thePacketCounts.ToArray(typeof(int)) as int[],
            thePacketData.ToArray(typeof(int)) as int[],
            thePacketDescription,
            theCustomRecognizerNode);

    return result;
}

平台

Windows Vista, Windows XP SP2, Windows Server 2003

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

InkAnalyzerBase 类

InkAnalyzerBase 成员

System.Windows.Ink.AnalysisCore 命名空间