I'm using a InkCanvas
with a record as you draw feature.
As you can see in this gif, created by drawing using a mouse:
When the user fires a PreviewMouseDown
event, I simply start the capture, frame by frame base on a time.
The capture is done by a simple render:
public static RenderTargetBitmap GetRender(this UIElement source, double dpi)
{
var bounds = VisualTreeHelper.GetDescendantBounds(source);
var scale = Math.Round(dpi / 96d, 2);
var width = (bounds.Width + bounds.X) * scale;
var height = (bounds.Height + bounds.Y) * scale;
#region If no bounds
if (bounds.IsEmpty)
{
var control = source as Control;
if (control != null)
{
width = control.ActualWidth * scale;
height = control.ActualHeight * scale;
}
bounds = new Rect(new System.Windows.Point(0d, 0d), new System.Windows.Point(width, height));
}
#endregion
var rtb = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), dpi, dpi, PixelFormats.Pbgra32);
var dv = new DrawingVisual();
using (var ctx = dv.RenderOpen())
{
var vb = new VisualBrush(source);
var locationRect = new System.Windows.Point(bounds.X, bounds.Y);
var sizeRect = new System.Windows.Size((int)Math.Round(bounds.Width), (int)Math.Round(bounds.Height));
ctx.DrawRectangle(vb, null, new Rect(locationRect, sizeRect));
}
rtb.Render(dv);
return (RenderTargetBitmap)rtb.GetAsFrozen();
}
Now, the problem is that when using touch, for some reason, the strokes are not available when the render occurs. But they are being displayed normally for me:
As you can see, the recorder still captures all necessary frames, but the strokes are only "there" when the PreviewMouseUp
event occurs.
What can I do to fix this issue?