Share via


InkManager.LoadAsync(IInputStream) 方法

定义

注意

对于使用可扩展应用程序标记语言 (XAML) 的通用 Windows 应用,建议使用 InkPresenterInkCanvas 控件,而不是 InkManager

将所有 InkStroke 对象从指定流异步加载到 InkManager 管理的 InkStroke 集合。

墨迹数据作为墨迹序列化格式 (ISF) 元数据,并嵌入到图形交换格式 (GIF) 文件中。

public:
 virtual IAsyncActionWithProgress<unsigned long long> ^ LoadAsync(IInputStream ^ inputStream) = LoadAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncActionWithProgress<uint64_t> LoadAsync(IInputStream const& inputStream);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncActionWithProgress<ulong> LoadAsync(IInputStream inputStream);
function loadAsync(inputStream)
Public Function LoadAsync (inputStream As IInputStream) As IAsyncActionWithProgress(Of ULong)

参数

inputStream
IInputStream

包含笔划集合的流。 IRandomAccessStream (要求改为指定 IOutputStream) 对象。

返回

IAsyncActionWithProgress<UInt64>

Windows.Foundation.IAsyncActionWithProgress

IAsyncActionWithProgress<uint64_t>

异步操作的状态,即提取的字节数。 有关详细信息,请参阅 ReadAsync 方法。

实现

属性

示例

loadStrokes此示例中的 函数演示了如何:

  • 显示文件打开屏幕,其中文件类型使用 FileOpenPicker 对象限制为图形交换格式 (GIF) 格式。
  • 通过 OpenAsync 方法设置输入流。
  • 使用 InkManager 对象的 LoadAsync 方法 (inkManager) () 的图形交换格式 (GIF) 文件 storageFile 对墨迹数据进行反序列化。
// Load strokes into an inkManager.
function loadStrokes()
{
    // Set up the file open screen.
    var openPicker = Windows.Storage.Pickers.FileOpenPicker();
    openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary;
    openPicker.fileTypeFilter.replaceAll([".gif"]);

    // Set up the stream.
    var loadStream = null;

    // Asynchronously load the ink data from the stream.
    openPicker.pickSingleFileAsync().done(
        function (file)
        {
            if (null != file)
            {
                file.openAsync(Windows.Storage.FileAccessMode.read).then(
                    function (stream) {
                        loadStream = stream;
                        return inkManager.loadAsync(loadStream);
                    }).done(
                        function()
                        {
                            var strokes = inkManager.getStrokes().length;
                            if (strokes === 0)
                            {
                                statusMessage.innerText = "No strokes in file.";
                            }
                            else
                            {
                                statusMessage.innerText = strokes + " strokes loaded.";
                            }
                            renderAllStrokes();
                            loadStream.close();
                        },
                        function (e)
                        {
                            statusMessage.innerText = "Load failed.";
                            if (loadStream)
                            {
                                // Close the stream if open.
                                loadStream.close();
                            }
                        });
            }
        });
}

注解

将元数据嵌入图形交换格式 (GIF) 文件中,可以在未启用墨迹的应用程序中查看墨迹,同时保持已启用墨迹的应用程序的完全保真度。 此格式非常适合在 HTML 文件中传输墨迹内容,并使其可供墨迹和非墨迹应用程序使用。

注意

墨迹序列化格式 (ISF) 是墨迹最紧凑的持久表示形式。 它可以嵌入到二进制文档格式中,也可以直接放置在剪贴板中,同时保留各种墨迹属性,例如压力、宽度、颜色、倾斜、扭曲等。

适用于

另请参阅