如何细化inkpresenter WP8的笔画

时间:2013-10-15 10:37:23

标签: windows-phone-8 stroke presenter microsoft.ink

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

    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;
    }

1 个答案:

答案 0 :(得分:0)

您可以在此Download link

中找到描述墨水展示器的示例源代码

。请找到下载标签。此外,它还包含大量其他样本,可帮助您更深入地学习Windows手机。