设为首页 加入收藏

TOP

背水一战 Windows 10 (62) - 控件(媒体类): InkCanvas 保存和加载, 手写识别(二)
2017-10-10 12:46:35 】 浏览:9133
Tags:背水一战 Windows 控件 媒体 InkCanvas 保存 加载 手写 识别
", new List<string>() { ".ink" }); // 弹出文件保存对话框 var file = await picker.PickSaveFileAsync(); if (file == null) return; // 在调用 CompleteUpdatesAsync 之前,阻止对文件的更新 CachedFileManager.DeferUpdates(file); // Stream 转 byte[] DataReader reader = new DataReader(stream.GetInputStreamAt(0)); await reader.LoadAsync((uint)stream.Size); byte[] bytes = new byte[stream.Size]; reader.ReadBytes(bytes); // 写入文件 await FileIO.WriteBytesAsync(file, bytes); // 保存文件 await CachedFileManager.CompleteUpdatesAsync(file); } private async void load_Click(object sender, RoutedEventArgs e) { // 文件打开对话框 var picker = new FileOpenPicker { SuggestedStartLocation = PickerLocationId.DocumentsLibrary }; picker.FileTypeFilter.Add(".ink"); // 弹出文件打开对话框 var pickedFile = await picker.PickSingleFileAsync(); if (pickedFile != null) { // 读取涂鸦数据 IRandomAccessStreamWithContentType stream = await pickedFile.OpenReadAsync(); // 加载指定的涂鸦数据 await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(stream); } } } }


2、演示 InkCanvas 涂鸦板的手写识别
Controls/MediaControl/InkCanvasDemo4.xaml

<Page
    x:Class="Windows10.Controls.MediaControl.InkCanvasDemo4"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Windows10.Controls.MediaControl"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Transparent">
        <StackPanel Margin="10 0 10 10">

            <Border Background="White" Width="480" Height="320" Margin="5" HorizontalAlignment="Left">
                <!--
                    InkCanvas - 涂鸦板控件
                -->
                <InkCanvas Name="inkCanvas" />
            </Border>

            <Button Name="recognize" Content="手写识别" Margin="5" Click="recognize_Click" />

            <TextBlock Name="lblMsg" Margin="5" />

        </StackPanel>
    </Grid>
</Page>

Controls/MediaControl/InkCanvasDemo4.xaml.cs

/*
 * InkCanvas - 涂鸦板控件(继承自 FrameworkElement, 请参见 /Controls/BaseControl/FrameworkElementDemo/)
 *     InkPresenter - 获取 InkPresenter 对象
 *        
 * InkRecognizerContainer - 用于管理手写识别
 *     GetRecognizers() - 获取 InkRecognizer 对象集合
 *     SetDefaultRecognizer(InkRecognizer recognizer) - 将指定的 InkRecognizer 设置为默认的手写识别器
 *     RecognizeAsync(InkStrokeContainer strokeCollection, InkRecognitionTarget recognitionTarget) - 识别,返回 InkRecognitionResult 对象集合
 *         InkStrokeContainer strokeCollection - 需要识别的 InkStrokeContainer 对象
 *         InkRecognitionTarget recognitionTarget - 需要识别的目标
 *             All - 识别全部涂鸦数据
 *             Selected - 识别被选中的涂鸦数据
 *             Recent - 识别 InkStroke 的 Recognized 为 false 的涂鸦数据
 *             
 * InkRecognizer - 手写识别器
 *     Name - 手写识别器的名字(只读)
 * 
 * InkRecognitionResult - 手写识别结果
 *     BoundingRect - 获取用于识别的涂鸦的 Rect 区域
 *     GetStrokes() - 获取用于识别的 InkStroke 对象集合
 *     GetTextCandidates() - 获取识别结果,这是一个候选结果列表
 * 
 * InkPresenter - 涂鸦板
 *     StrokeContainer - 返回 InkStrokeContainer 类型的对象
 *     
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Fiddler 抓包https配置 提示creat.. 下一篇C#连接数据库MD5数据库加密

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目