0

我有一种绘图应用程序。线条绘制在触摸输入上。

      void Touch_FrameReported(object sender, TouchFrameEventArgs e)
      {
        int pointsNumber = e.GetTouchPoints(InkCanvas2).Count;
        TouchPointCollection pointCollection = e.GetTouchPoints(InkCanvas2);

        for (int i = 0; i < pointsNumber; i++)
        {
            if (pointCollection[i].Action == TouchAction.Down)
            {
                preXArray[i] = pointCollection[i].Position.X;
                preYArray[i] = pointCollection[i].Position.Y;
            }
            if (pointCollection[i].Action == TouchAction.Move)
            {
                Line line = new Line();


                line.X1 = preXArray[i];
                line.Y1 = preYArray[i];
                line.X2 = pointCollection[i].Position.X;
                line.Y2 = pointCollection[i].Position.Y;

                line.Stroke = StrokeColorBrush;
                line.Fill = StrokeColorBrush;
                line.StrokeThickness = StrokeWidth;
                line.StrokeDashCap = PenLineCap.Round;
                line.StrokeStartLineCap = PenLineCap.Round;
                line.StrokeEndLineCap = PenLineCap.Round;

                InkCanvas2.Children.Add(line);

                preXArray[i] = pointCollection[i].Position.X;
                preYArray[i] = pointCollection[i].Position.Y;

                Brush aSolidBrush = new SolidColorBrush(Colors.Black);

            }
        }

鼠标事件

    void InkCanvas2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        currentPoint = e.GetPosition(InkCanvas2);
        oldPoint = currentPoint;
    }


    void InkCanvas2_MouseMove(object sender, MouseEventArgs e)
    {
        currentPoint = e.GetPosition(this.InkCanvas2);

        Line line = new Line() { X1 = currentPoint.X, Y1 = currentPoint.Y, X2 = oldPoint.X, Y2 = oldPoint.Y };
        line.Stroke = StrokeColorBrush;
        line.StrokeThickness = StrokeWidth;

        line.StrokeStartLineCap = PenLineCap.Round;
        line.StrokeEndLineCap = PenLineCap.Round;
        line.StrokeLineJoin = PenLineJoin.Round;

        this.InkCanvas2.Children.Add(line);
        oldPoint = currentPoint;
    }

我已经清楚了

 InkCanvas2.Children.Clear();

现在我试图实现一个橡皮擦功能,然后我画线,它应该擦除那些部分。我尝试将颜色更改为透明,但这不起作用。有什么建议么?

4

1 回答 1

0

你可以这样做:

inkCanvas2.EditingMode = InkCanvasEditingMode.EraseByPoint;
于 2013-06-11T06:53:13.557 回答