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));
}
}
示例代码
参考资料
官方资料
Get Started with Ink in WPF
Handwriting Recognition
引用问题
WPF Handwriting .NET 4.5 Windows 8: Missing IAWinFX.dll and others
学习技术最好的文档就是【官方文档】,没有之一。
还有学习资料【Microsoft Learn】、【CSharp Learn】、【My Note】。
如果,你认为阅读这篇博客让你有些收获,不妨点击一下右下角的【推荐】按钮。
如果,你希望更容易地发现我的新博客,不妨点击一下【关注】。