I use InkCanvas in my UWP application that I developed as a Windows 10 App. I am successfully saving the drawing in JPG format to LocalStorage.
I want to load the drawing into the InkCanvas object so that it can be selected and rearranged over the DataGrid. I am encountering the following error.
Thank you so much if you help.
Exception:
{System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component. at Windows.UI.Input.Inking.InkStrokeContainer.LoadAsync(IInputStream inputStream) at TICAppUWP.CoverPage.canvasFileNotes()}
Save:
StorageFolder storageFolder = await StorageFolder.GetFolderFromPathAsync(fileNotesFolderPath);
string fileName = App._PreparedFor +"_"+ App._Date + "_PageID_" + App._CoverPageID;
var file = await storageFolder.CreateFileAsync(fileName + ".jpg", CreationCollisionOption.ReplaceExisting);
CanvasDevice device = CanvasDevice.GetSharedDevice();
CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, (int)myInkCanvas.ActualWidth, (int)myInkCanvas.ActualHeight, 96);
using (var ds = renderTarget.CreateDrawingSession())
{
ds.Clear(Windows.UI.Colors.White);
ds.DrawInk(myInkCanvas.InkPresenter.StrokeContainer.GetStrokes());
}
using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
await renderTarget.SaveAsync(fileStream, CanvasBitmapFileFormat.Jpeg, 1f);
}
Load:
StorageFolder storageFolder = await StorageFolder.GetFolderFromPathAsync(fileNotesFolderPath);
string fileName = App._PreparedFor + "_" + App._Date + "_PageID_" + App._CoverPageID;
var file = await storageFolder.GetFileAsync(fileName + ".jpg");
StorageFile inkFile = await storageFolder.GetFileAsync(fileName + ".jpg");
if (file != null)
{
Windows.Storage.Streams.IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
using (var inputStream = stream.GetInputStreamAt(0))
{
await myInkCanvas.InkPresenter.StrokeContainer.LoadAsync(stream);
}
stream.Dispose();
}