0

I'm using ink presenter to draw the strokes. But the problem is while drawing curved lines, its draws jagged lines.. Straight lines do not have a problem. This is how I have done.. I dont know where to make changes so as to make the lines smoother.

    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;
    }
leesei
  • 6,020
  • 2
  • 29
  • 51
alfah
  • 2,077
  • 1
  • 31
  • 55

1 Answers1

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.

WinPhone Artist
  • 280
  • 1
  • 2
  • 10