0

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:

With 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:

With touch

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?

Nicke Manarin
  • 3,026
  • 4
  • 37
  • 79
  • Did you try to handle the `PreviewTouchDown` event? – mm8 Apr 02 '19 at 12:34
  • Yes, both `PreviewTouchDown` and `PreviewMouseDown` are working as expected. The issue is that the ink renderer isn't making the ink available before the `PreviewXXXXUp` event is fired. – Nicke Manarin Apr 02 '19 at 13:40
  • I believe it has something to do with the fact that there is a gesture recognizer, maybe it's not releasing the ink stroke because it needs to recognize first if it's a gesture or not? I'm not sure. – Nicke Manarin Apr 02 '19 at 13:42

0 Answers0