0

我正在使用墨水演示器来绘制笔画。但问题是在绘制曲线时,它会绘制锯齿线。直线没有问题。这就是我所做的......我不知道在哪里进行更改以使线条更平滑。

    private void MyIP_MouseLeftButtonDown(object sender, MouseEventArgs e)
    {
        MyIP.CaptureMouse();

        DrawingAttributes att = new DrawingAttributes();
        att.Color = CB;
        att.Width = StrokeWidth;
        att.Height = StrokeWidth;


        if (bErase == true)
        {
            StylusPointCollection ErasePointCollection = new StylusPointCollection();
            ErasePointCollection.Add(e.StylusDevice.GetStylusPoints(MyIP));
            lastPoint = ErasePointCollection[ErasePointCollection.Count - 1];
            EraseStroke = new Stroke(ErasePointCollection);

            EraseStroke.DrawingAttributes = att;

        }
        else
        {
            StylusPointCollection MyStylusPointCollection = new StylusPointCollection();
            MyStylusPointCollection.Add(e.StylusDevice.GetStylusPoints(MyIP));
            NewStroke = new Stroke(MyStylusPointCollection);

            NewStroke.DrawingAttributes = att;

            MyIP.Strokes.Add(NewStroke);
        }
    }

    //StylusPoint objects are collected from the MouseEventArgs and added to MyStroke. 
    private void MyIP_MouseMove(object sender, MouseEventArgs e)
    {
        if (bErase == true)
        {
            //StylusPointCollection pointErasePoints = e.StylusDevice.GetStylusPoints(MyIP);
            //EraseStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(MyIP));

            //pointErasePoints.Insert(0, lastPoint);
            //StrokeCollection hitStrokes = MyIP.Strokes.HitTest(pointErasePoints);
            //if (hitStrokes.Count > 0)
            //{
            //    foreach (Stroke hitStroke in hitStrokes)
            //    {

            //        ////For each intersecting stroke, split the stroke into two while removing the intersecting points.
            //        ProcessPointErase(hitStroke, pointErasePoints);
            //    }
            //}
            //lastPoint = pointErasePoints[pointErasePoints.Count - 1];

            //STROKEERASE METHOD

            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);
                    undoStack.Push(hitStroke);
                    undoStateBufferStack.Push(true);
                }
            }

        }

        if (NewStroke != null)
            NewStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(MyIP));

    }

    //MyStroke is completed
    private void MyIP_LostMouseCapture(object sender, MouseEventArgs e)
    {
        if (NewStroke != null)
        {
            undoStack.Push(NewStroke);
            undoStateBufferStack.Push(false);
        }

        EraseStroke = null;
        NewStroke = null;

    }

    //Set the Clip property of the inkpresenter so that the strokes
    //are contained within the boundary of the inkpresenter
    private void SetBoundary()
    {
        RectangleGeometry MyRectangleGeometry = new RectangleGeometry();
        MyRectangleGeometry.Rect = new Rect(0, 0, MyIP.ActualWidth, MyIP.ActualHeight);
        MyIP.Clip = MyRectangleGeometry;
    }
4

1 回答 1

0

You can find the sample source code describing ink presenter in this Download link

. Please find the download tag. Also it contains plenty other samples which helps you to learn windows phone deeper.

于 2013-10-15T11:01:57.490 回答