积极答复者
还是一个InkCanvas的问题,关于橡皮擦功能的

问题
-
private Point leftTop;
private Point rightBottom;
public Point LeftTop
{
get { return leftTop; }
set { leftTop = value; }
}
public Point RightBottom
{
get { return rightBottom; }
set { rightBottom = value; }
}
public DrawEllipse(StylusPointCollection pts, DrawingAttributes da)
: base(pts, da)
{
this.StylusPoints = pts;
this.DrawingAttributes = da;
}protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
{
if (drawingContext == null)
{
throw new ArgumentNullException("drawingContext");
}
if (null == drawingAttributes)
{
throw new ArgumentNullException("drawingAttributes");
}
Pen pen = new Pen
{
StartLineCap = PenLineCap.Round,
EndLineCap = PenLineCap.Round,
Brush = new SolidColorBrush(ObjectColor),
Thickness = LineWidth
};
LeftTop = new Point(StylusPoints[0].X, StylusPoints[0].Y);
RightBottom = new Point(StylusPoints[1].X, StylusPoints[1].Y);
Rect r = new Rect(
LeftTop,
RightBottom);
Point center = new Point(
(r.Left + r.Right) / 2.0,
(r.Top + r.Bottom) / 2.0);
double radiusX = (r.Right - r.Left) / 2.0;
double radiusY = (r.Bottom - r.Top) / 2.0;
drawingContext.DrawEllipse(
backgroundBrush(BgColorHelper),
pen,
center,
radiusX,
radiusY);
}
}当使用橡皮擦的时候,就是inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint 或者 ByStroke
的时候 会出现这样的情况,没有其他功能性代码,只有画得
我在DrawCore中判断,如果是橡皮擦状态就retrun了,他照样这样,上图
这是画圆
使用橡皮擦以后
我做过判断,如果橡皮碰到这个圆,就从inkcanvas中移除,但是没有用,还是这样...
这个是例子,上次发过的,那时候,没注意这个问题 InkCanvasSample
Hero
答案
-
我测试了下, inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke; 效果还是可以的,在橡皮擦划过图形的时候能够擦掉,不过 EraseByPoint 是有问题。
为什么,因为 EraseByPoint 擦除的只是他经过的Stroke的上面的点,如果一个园形的上面几个点被擦掉,你的 DrawCore 就会根据剩余的点来重新画出新的两个圆来。这个是符合逻辑的,所以你如果是依据Stroke来擦除,应该设置 inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke; 而不是 EraseByPoint 。
还有擦除动作需要整个橡皮擦经过Stroke的范围,而不是一碰就擦。因为我们的Stroke不想默认的线条了,他的每一个点都是可以感应擦除的,我们的是一个整体,只有整体接受到擦除动作才会被擦除。
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 HeroHua0509 2011年8月29日 6:03
-
你好Bob Bao
经过你得讲解我了解了原理 但是因为项目原因,
我不能使用两种模式的橡皮擦 所以我使用了下面的方法
在擦出前判断是一般的Stroke还是形状,如果是形状,直接移除,就不让它使用自带的擦出功能了
void DrawingInkCanvas_StrokeErasing(object sender, InkCanvasStrokeErasingEventArgs e)
{
//这里有判断 this.Strokes.Remove(e.Stroke); return;
}
结贴了哦
Hero- 已标记为答案 Jie BaoModerator 2011年8月29日 5:53
- 已编辑 HeroHua0509 2011年8月29日 6:04
全部回复
-
我测试了下, inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke; 效果还是可以的,在橡皮擦划过图形的时候能够擦掉,不过 EraseByPoint 是有问题。
为什么,因为 EraseByPoint 擦除的只是他经过的Stroke的上面的点,如果一个园形的上面几个点被擦掉,你的 DrawCore 就会根据剩余的点来重新画出新的两个圆来。这个是符合逻辑的,所以你如果是依据Stroke来擦除,应该设置 inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke; 而不是 EraseByPoint 。
还有擦除动作需要整个橡皮擦经过Stroke的范围,而不是一碰就擦。因为我们的Stroke不想默认的线条了,他的每一个点都是可以感应擦除的,我们的是一个整体,只有整体接受到擦除动作才会被擦除。
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 HeroHua0509 2011年8月29日 6:03
-
你好Bob Bao
经过你得讲解我了解了原理 但是因为项目原因,
我不能使用两种模式的橡皮擦 所以我使用了下面的方法
在擦出前判断是一般的Stroke还是形状,如果是形状,直接移除,就不让它使用自带的擦出功能了
void DrawingInkCanvas_StrokeErasing(object sender, InkCanvasStrokeErasingEventArgs e)
{
//这里有判断 this.Strokes.Remove(e.Stroke); return;
}
结贴了哦
Hero- 已标记为答案 Jie BaoModerator 2011年8月29日 5:53
- 已编辑 HeroHua0509 2011年8月29日 6:04
-
是个好方法。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.