UWP 手写板InkCanvas

效果如图

关键代码

<InkCanvas x:Name="inkCanvas" />
//设置绘画信息
inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;
InkDrawingAttributes inkDrawingAttributes = inkCanvas.InkPresenter.CopyDefaultDrawingAttributes();
inkDrawingAttributes.Size = new Size(8, 8);
inkDrawingAttributes.Color = Windows.UI.Color.FromArgb(255, 112, 112, 112);
inkDrawingAttributes.FitToCurve = true;
inkDrawingAttributes.PenTip = PenTipShape.Rectangle;
inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(inkDrawingAttributes);
InkRecognizerContainer inkRecognizerContainer = new InkRecognizerContainer();
IReadOnlyList<InkRecognizer> recognizers = inkRecognizerContainer.GetRecognizers();
InkRecognizer recognizer = recognizers.SingleOrDefault(r => r.Name == "Microsoft 中文(简体)手写识别器");
inkRecognizerContainer.SetDefaultRecognizer(recognizer);
if (token.IsCancellationRequested)
    return;

IReadOnlyList<InkRecognitionResult> results = await inkRecognizerContainer.RecognizeAsync(inkCanvas.InkPresenter.StrokeContainer, InkRecognitionTarget.All);

foreach (InkRecognitionResult result in results)
{
    //获得识别结果
    foreach (string text in result.GetTextCandidates())
    {
        
    }
}

示例代码

HandwritingDemo

参考资料

Ink Analysis sample
InkAnalysis

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