【发布时间】: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