使用touch时,InkCanvas在PreviewMouseUp之前不提交笔划

时间:2019-04-02 01:59:41

标签: c# wpf touch inkcanvas

我正在使用带有{em>记录时绘制功能的InkCanvas。 如您在此gif中看到的那样,该效果是通过使用鼠标进行绘制而创建的:

With mouse

当用户触发PreviewMouseDown事件时,我只是按时间逐帧开始捕获。

捕获是通过一个简单的渲染完成的:

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();
}

现在,问题在于使用触摸时,由于某种原因,在进行渲染时笔触不可用。但是它们正在为我正常显示:

With touch

如您所见,记录器仍会捕获所有必需的帧,但是当发生PreviewMouseUp事件时,笔画只是“有”。

该如何解决此问题?

0 个答案:

没有答案