I have a ScrollViewer which contains a CanvasVirtualControl. My app does the following:
- Use an InkCanvas to draw wet ink
- Custom dry the ink and render it offscreen on a CanvasRenderTarget
- Then draw the appropriate portion the target onto a CanvasVirtualControl
- When user pinch zoom, the entire canvas is invalidated, then the
DpiScale of the canvas is changed and a new render target is created with the new dpi. Then finally the entire canvas is repainted.
This works ok, but the problem occurs in the fourth step. When I scale the canvas and then invalidate the entire canvas to redraw it again, the rendering quality of the ink strokes is incredibly poor. I notice that if I draw a new ink stroke at a certain zoom level (with appropriate dpi) then the new ink stroke is rendered perfectly fine, but the old ink strokes are rendered poorly.
This is the code that gets called in step 4:
private void canvasControl_RegionsInvalidated(Microsoft.Graphics.Canvas.UI.Xaml.CanvasVirtualControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasRegionsInvalidatedEventArgs args)
{
bool createRenderTarget = (this.renderTarget == null);
if (createRenderTarget)
{
this.renderTarget = new CanvasRenderTarget(
this.canvasControl, // the canvasControl has new dpi now
this.canvasControl.Size);
}
foreach (var region in args.InvalidatedRegions)
{
using (var renderSession = renderTarget.CreateDrawingSession())
{
if (createRenderTarget)
{
// have to clear out the render target on first use.
renderSession.Clear(Windows.UI.Colors.Transparent);
}
Debug.WriteLine(updateStrokes.Count);
renderSession.DrawInk(updateStrokes);
}
using (var ds = sender.CreateDrawingSession(region))
{
float opacity = 1.0F;
ds.DrawImage(renderTarget, region, region, opacity, CanvasImageInterpolation.HighQualityCubic);
}
}
}
Here is a picture of what I am seeing (the canvas has been zoomed and a new ink stroke is drawn), I noticed that the rendering quality decreases when the user scales down the canvas (and then scale up).