WPF 手写板

效果如图

引用

IACore.dll
IALoader.dll
IAWinFX.dll
Microsoft.Ink.Analysis.dll
Microsoft.Ink.dll
System.Windows.Interactivity.dll

关键代码

通过RecognizeCommand获得StrokeCollection,笔画集合

<InkCanvas x:Name="inkCanvas" Background="Transparent">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="StrokeCollected">
            <i:InvokeCommandAction Command="{Binding RecognizeCommand}" CommandParameter="{Binding Strokes, ElementName=inkCanvas}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <InkCanvas.DefaultDrawingAttributes>
        <DrawingAttributes>
            <DrawingAttributes.Width>8</DrawingAttributes.Width>
            <DrawingAttributes.Height>8</DrawingAttributes.Height>
            <DrawingAttributes.Color>#707070</DrawingAttributes.Color>
            <DrawingAttributes.StylusTip>Rectangle</DrawingAttributes.StylusTip>
            <DrawingAttributes.FitToCurve>True</DrawingAttributes.FitToCurve>
        </DrawingAttributes>
    </InkCanvas.DefaultDrawingAttributes>
</InkCanvas>

使用InkAnalyzer得到预测多个结果

Stroke stroke = GetCombinedStore(strokes);

using (InkAnalyzer analyzer = new InkAnalyzer())
{
    analyzer.AddStroke(stroke, ChsLanguageId);
    analyzer.SetStrokeType(stroke, StrokeType.Writing);

    AnalysisStatus status = analyzer.Analyze();

    if (status.Successful)
    {
        foreach (string item in analyzer.GetAlternates().OfType<AnalysisAlternate>().Select(x => x.RecognizedString).ToArray())
            if (Alternates.Count < MAX_Alternates_COUNT)
                Alternates.Add(new AlternateViewModel(this,item));
    }
}

示例代码

HandwritingDemo

参考资料

官方资料
Get Started with Ink in WPF
Handwriting Recognition
引用问题
WPF Handwriting .NET 4.5 Windows 8: Missing IAWinFX.dll and others

posted @ 2022-02-17 19:26  Lulus  阅读(441)  评论(0编辑  收藏  举报