[英]Windows 8.1 store xaml save InkManager in a string
我正在嘗試將用鉛筆繪制的內容保存為字符串,然后通過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();
但它返回一個空字符串。
在這里找到答案:
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();
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.