我正在使用InkPresenter使用画布在图像上绘制笔划。它很棒。现在我可以通过触摸笔划的任何一点来擦除我想要的任何笔划。但我需要擦掉一部分中风。我看到几个商店wp应用程序可以做到这一点。怎么可能。这是我的代码。
Stroke NewStroke;
double strokeSize = 4;
Color drawingColor = Colors.White;
private enum EditState { Draw, Erase, Effect };
private void StartDrawing_MouseEnter(object sender, MouseEventArgs e) {
try
{
if (crtState == EditState.Draw) {
MyIP.CaptureMouse();
StylusPointCollection MyStylusPointCollection = new StylusPointCollection();
MyStylusPointCollection.Add(e.StylusDevice.GetStylusPoints(MyIP));
NewStroke = new Stroke(MyStylusPointCollection);
NewStroke.DrawingAttributes.Color = drawingColor;
NewStroke.DrawingAttributes.Height = strokeSize;
NewStroke.DrawingAttributes.Width = strokeSize;
MyIP.Strokes.Add(NewStroke);
StylusPointCollection ErasePointCollection = new StylusPointCollection();
}
else if(crtState == EditState.Erase) {
MyIP.CaptureMouse();
StylusPointCollection pointErasePoints = e.StylusDevice.GetStylusPoints(MyIP);
StrokeCollection hitStrokes = MyIP.Strokes.HitTest(pointErasePoints);
if (hitStrokes.Count > 0)
foreach (Stroke hitStroke in hitStrokes)
MyIP.Strokes.Remove(hitStroke);
}
}
catch (Exception) { }
}
private void MyIP_MouseMove(object sender, MouseEventArgs e)
{
if (crtState == EditState.Erase) {
StylusPointCollection pointErasePoints = e.StylusDevice.GetStylusPoints(MyIP);
StrokeCollection hitStrokes = MyIP.Strokes.HitTest(pointErasePoints);
if (hitStrokes.Count > 0)
foreach (Stroke hitStroke in hitStrokes)
MyIP.Strokes.Remove(hitStroke);
}
if (crtState==EditState.Draw && NewStroke != null)
NewStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(MyIP));
}
private void MyIP_MouseLeave(object sender, MouseEventArgs e)
{
NewStroke = null;
}