Win2D is an easy-to-use Windows Runtime API for immediate mode 2D graphics rendering with GPU acceleration. It is available to C#, C++ and VB developers writing apps for the Windows Universal Platform (UWP). It utilizes the power of Direct2D, and integrates seamlessly with XAML and CoreWindow.
So I have a CanvasVirtualControl in my app that I am using to draw ink over, using a standard InkCanvas I retrieved a InkSynchronizer. Then when the strokes are collected, I invalidate the bounding rect of the stroke inside my CanvasVirtualControl and then handle the RegionsInvalidated event as follows:
private void canvasControl_RegionsInvalidated(CanvasVirtualControl sender, CanvasRegionsInvalidatedEventArgs args)
{
foreach (var region in args.InvalidatedRegions)
{
using (var ds = sender.CreateDrawingSession(region))
{
List<InkStroke> strokesToDraw = new List<InkStroke>();
foreach (var stroke in inkStrokeContainer.GetStrokes())
{
var regionRect = region;
regionRect.Intersect(stroke.BoundingRect);
if(!regionRect.IsEmpty)
{
strokesToDraw.Add(stroke);
}
}
this.wetInkStrokes = null;
System.Diagnostics.Debug.WriteLine("Strokes to draw " + strokesToDraw.Count);
ds.DrawInk(strokesToDraw);
if (strokesToDraw.Count != 0)
{
this.inkSync.EndDry(); // exceptions gets thrown here (BeginDry() is called in onStrokesCollected
}
}
}
}
This seems to work ok, but when I can change the DPI of my CanvasVirtualControl I get the following error:
System.InvalidOperationException
HResult=0x8000000E
Message=A method was called at an unexpected time. (Exception from HRESULT: 0x8000000E)
Source=Windows
StackTrace:
at Windows.UI.Input.Inking.InkSynchronizer.EndDry()
at CanvasTesting.MainPage.canvasControl_RegionsInvalidated(CanvasVirtualControl sender, CanvasRegionsInvalidatedEventArgs args) in
So I have a
CanvasVirtualControl
in my app that I am using to draw ink over, using a standardInkCanvas
I retrieved aInkSynchronizer
. Then when the strokes are collected, I invalidate the bounding rect of the stroke inside my CanvasVirtualControl and then handle the RegionsInvalidated event as follows:This seems to work ok, but when I can change the DPI of my CanvasVirtualControl I get the following error: