1

I'm trying to save what i have drawn with the pencil as a string , and i do this by SaveAsync() method to put it in an IOutputStream then convert this IOutputStream to a stream using AsStreamForWrite() method from this point things should go fine, however i get a lot of problems after this part , if i use for example this code block:

  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
                }

i get this exception

"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." 

or if i try to convert the stream into an image using InMemoryRandomAccessStream like this:

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

my InMemoryRandomAccessStream variable is always zero in size.

also tried

StreamReader.ReadToEnd();

but it returns an empty string.

user2469133
  • 1,940
  • 3
  • 21
  • 33

1 Answers1

0

found the answer here :

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(); 
        }
    }
}
}
user2469133
  • 1,940
  • 3
  • 21
  • 33
  • Have you implemented the `WriteInk()` method from the link above? If yes what's the signature of the method calling `WriteInk()`? `WriteInk()` is failing after `await m_InkCanvas.SaveAsync(stream);` and a Catastophic Failure is being thrown when calling `WriteInk()'. Any idea how to solve it? Here's my question: http://stackoverflow.com/questions/30751449/save-taskstring-type-to-string-giving-catastrophic-failure – yalematta Jun 11 '15 at 12:56