I have an InkCanvas
drawing, which i convert to WriteableBitmap
and set is as an ImageSource
as follows:
MemoryStream ms = new MemoryStream();
await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(ms.AsOutputStream());
ms.Position = 0;
WriteableBitmap wb = new WriteableBitmap((int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight);
wb.SetSource(ms.AsRandomAccessStream());
image.Source = wb;
That works fine.
Now i need to store the WriteableBitmap
as a byte array in database in order to use it as image source of a GridView
item. This is the method i use to convert the bitmap to byte[]:
using (Stream stream = ((WriteableBitmap)image.Source).PixelBuffer.AsStream())
{
data = new byte[(uint)stream.Length];
await stream.ReadAsync(data, 0, data.Length);
}
and this one to restore the bitmap form byte[]:
WriteableBitmap wb = new WriteableBitmap(200,200);
using (Stream stream = wb.PixelBuffer.AsStream())
{
await stream.WriteAsync(data, 0, data.Length);
}
Now here are the screenshots describes how the image looks after retrieving from InkCanvas and after retrieving from byte[]:
Will be grateful if someone faced that issue and has a solution.