自定义InkCanvas(MSDN代码示例无法正常工作) [英] Custom InkCanvas (MSDN Code Sample not working properly)

查看:190
本文介绍了自定义InkCanvas(MSDN代码示例无法正常工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在InkCanvas中使用自定义画笔.

I want to use custom brushes with the InkCanvas.

它们是MSDN的代码片段. ( http://msdn.microsoft.com/en-us/library/ms747347 .aspx )

Their is a code snippet from MSDN. (http://msdn.microsoft.com/en-us/library/ms747347.aspx)

如果我使用该代码并非常快速地移动鼠标,则会在笔刷(椭圆)之间留出空间:

If i use that code and move my mouse VERY fast i get space between the brushes(ellipses):

当然,我的问题是如何解决此问题,但我也很好奇为什么会发生这种情况(我想从中学习),我想也许我做错了什么,但是即使我剪切/粘贴了正在发生的示例.

And my question is of course how to fix this but I'm also curious why this is happening (I want to learn from it) I thought maybe i did something wrong but even if i cut/paste the example it's happening.

在阅读代码时我注意到的一件事是CustomStroke类中的注释

One little thing i noticed when reading the code was this comment in the CustomStroke class

// Draw linear gradient ellipses between
// all the StylusPoints in the Stroke

在我看来,它应该在点之间绘制椭圆,而不仅是在点之间.

Seems to me like it should draw ellipses between the points not only at the points.

我正在使用C#.NET.

I'm using C#.NET.

简而言之:

  • 为什么会这样
  • 帮我修复它:)

推荐答案

为什么会这样

示例中的自定义InkCanvas在每个收集的StrokePoint处绘制一个椭圆,但不尝试在它们之间绘制线条.标准InkCanvas控件是通过在给定点之间绘制线条来实现的.这就是为什么示例中的自定义InkCanvas实现会留下空白而内置的空白不会留下空白的原因.

The custom InkCanvas in the example draws an ellipse at every collected StrokePoint but makes no attempt to draw lines between them. The standard InkCanvas control is implemented by drawing lines between the points it is given. This is why the custom InkCanvas implementation from the example leaves gaps and the built-in one doesn't.

如何修复"它

可以轻松地扩展自定义代码以不留空隙:除了在每个点绘制椭圆形之外,它还可以在每对点之间绘制线条.

The custom code could easily be extended to not leave gaps: In addition to drawing ellipses at each point, it could draw lines between each pair of points.

绘制连接线的代码可能会在绘制椭圆的代码之前添加,如下所示:

Code to draw connecting lines might be added before the code to draw the ellipses, like this:

// Draw connecting lines
var geo = new StreamGeometry();
using(geoContext = geo.Open())
{
  geoContext.StartFigure(stylusPoints[0], false, false);
  geoContext.PolyLineTo(stylusPoints.Skip(1).Cast<Point>(), true, false);
}
drawingContext.DrawGeometry(null, connectingLinePen, geo);

// Draw ellipses
for(int i = 1; i < stylusPoints.Count; i++)
{
  ... etc ...

此代码通过构造折线StreamGeometry然后将其绘制到上下文中来工作.在这种情况下使用StreamGeometry通常比使用Polyline创建PathGeometry或直接在drawingCanvas上进行一堆DrawLine调用更为有效.

This code works by constructing a polyline StreamGeometry and then drawing it to the context. Using a StreamGeometry in this context is generally more efficient than creating a PathGeometry with a Polyline or doing a bunch of DrawLine calls directly on the drawingCanvas.

注意:使用更好的数字化仪将无法解决潜在的问题,因为自定义InkCanvas实际上旨在仅在采样点而不是在采样点之间显示数据.

Note: Using a better digitizer won't solve the underlying problem, which is that the custom InkCanvas is actually designed to only show data at the sampled points and not in between.

这篇关于自定义InkCanvas(MSDN代码示例无法正常工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆