Reputation: 184
So I am trying to serialize and deserialize an IReadOnlyList<InkStroke>
from Windows.UI.Input.Inking
for my UWP app, and I have used the following code to serialize the data:
var stream = new InMemoryRandomAccessStream();
await canvas.InkPresenter.StrokeContainer.SaveAsync(stream);
await stream.FlushAsync();
var buffer = new byte[stream.Size];
await stream.AsStream().ReadAsync(buffer, 0, buffer.Length);
return Convert.ToBase64String(buffer);
How can I deserialize this string to create an IInputStream
(or IRandomAccessStream
instead) which can be used in the StrokeContainer.LoadAsync()
method?
Upvotes: 2
Views: 12837
Reputation: 869
You can use the following piece of code....
byte[] bytes = Convert.FromBase64String(stringinput);
MemoryStream stream = new MemoryStream(bytes);
IInputStream is=stream.AsRandomAccessStream(); //It will return an IInputStream object
Upvotes: 3
Reputation: 331
Try this:
byte[] data = Convert.FromBase64String(encodedString);
InMemoryRandomAccessStream inputStream = new InMemoryRandomAccessStream();
await inputStream.WriteAsync(data.AsBuffer());
inputStream.Seek(0);
await canvas.InkPresenter.StrokeContainer.LoadAsync(inputStream);
Upvotes: 1