【问题标题】:Windows 8.1 store xaml save InkManager in a stringWindows 8.1 存储 xaml 将 InkManager 保存在字符串中
【发布时间】:2014-06-16 09:53:11
【问题描述】:

我正在尝试将我用铅笔绘制的内容保存为字符串,我通过 SaveAsync() 方法将其放入 IOutputStream 中,然后使用 AsStreamForWrite() 方法将此 IOutputStream 转换为流事情应该会很好,但是在这部分之后我会遇到很多问题,如果我使用例如这个代码块:

  using (var stream = new MemoryStream())
                {
                    byte[] buffer = new byte[2048]; // read in chunks of 2KB
                   int bytesRead = (int)size;
                    while (bytesRead < 0)
                    {
                        stream.Write(buffer, 0, bytesRead);

                    }
                    byte[] result = stream.ToArray();
                    // TODO: do something with the result
                }

我得到了这个异常

"Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection." 

或者如果我尝试使用 InMemoryRandomAccessStream 将流转换为图像,如下所示:

 InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
                await s.CopyToAsync(ras.AsStreamForWrite());

我的 InMemoryRandomAccessStream 变量的大小始终为零。

也试过

StreamReader.ReadToEnd();

但它返回一个空字符串。

【问题讨论】:

    标签: image xaml windows-store-apps drawing windows-8.1


    【解决方案1】:

    在这里找到答案:

    http://social.msdn.microsoft.com/Forums/windowsapps/en-US/2359f360-832e-4ce5-8315-7f351f2edf6e/stream-inkmanager-strokes-to-string

    private async void ReadInk(string  base64)
    {
    if (!string.IsNullOrEmpty(base64))
    {
        var bytes = Convert.FromBase64String(base64);
    
        using (var inMemoryRAS = new InMemoryRandomAccessStream())
        {
            await inMemoryRAS.WriteAsync(bytes.AsBuffer());
            await inMemoryRAS.FlushAsync();
            inMemoryRAS.Seek(0);
    
            await m_InkManager.LoadAsync(inMemoryRAS);
    
            if (m_InkManager.GetStrokes().Count > 0)
            {
                // You would do whatever you want with the strokes
                // RenderStrokes(); 
            }
        }
    }
    }
    

    【讨论】:

    • 您是否实现了上面链接中的WriteInk() 方法?如果是,调用WriteInk() 的方法的签名是什么? WriteInk()await m_InkCanvas.SaveAsync(stream); 之后失败,并且在调用“WriteInk()”时引发了灾难性故障。知道如何解决吗?这是我的问题:stackoverflow.com/questions/30751449/…
    猜你喜欢
    • 1970-01-01
    • 2014-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    相关资源
    最近更新 更多