0
votes

I have a problem to depict many mini-versions of my InkCanvas. In my app it is possible to write or draw on a InkCanvas. Now I want to depict all created InkCanvas in a GridView.

But with mini versions in this GridView i can not create enough mini versions.

I tested it with 36 mini versions and after I show one and navigate back, the App crashs everytime by rendering the same mini InkCanvas with the error: Insufficient Memory. So I searched an found this post:

Insufficient memory to continue the execution of the program when trying to initialize array of InkCanvas in UWP

I checked the Memory workload:

     var AppUsageLevel = MemoryManager.AppMemoryUsageLevel;
     var AppMemoryLimit = MemoryManager.AppMemoryUsageLimit;

and the memory has enough free space. (is this a bug?)

So I tried to render a image from my grid with a InkCanvas but the strokes were not rendered and all pictures were empty. ( can I save Memory this way?)

So now my question is:

Can someone tell me how to solve this problem? And what is the best way?

Thank you very much in advance!

Agredo

1

1 Answers

1
votes

If you want to preview your drawings, better way is to render them to bitmap and show this bitmaps in grid instead of multiple complex controls InkCanvas is.

Here is some code to render inks to bitmap from another SO Answer:

CanvasDevice device = CanvasDevice.GetSharedDevice();
CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, (int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight, 96);

using (var ds = renderTarget.CreateDrawingSession())
{
    ds.Clear(Colors.White);
    ds.DrawInk(inkCanvas.InkPresenter.StrokeContainer.GetStrokes());
}

using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
    await renderTarget.SaveAsync(fileStream, CanvasBitmapFileFormat.Jpeg, 1f);

You also need to add Win2D.uwp nuget package to your project.