Beispiel #1
0
        private void drawLine(Point p1, Point p2)
        {
            List <Point> controlPoints = BezierHelper.getControlPoints(0.4, p1, p2);

            if (isHaveLastControlPoint == false)
            {
                lastControlPoint       = p1;
                isHaveLastControlPoint = true;
            }

            QuadraticBezierSegment bezierSegment = new QuadraticBezierSegment(p1, controlPoints[0], true);

            lastControlPoint = controlPoints[1];
            pathFigure.Segments.Add(bezierSegment);
            LineSegment lineSegment = new LineSegment(controlPoints[1], true);

            pathFigure.Segments.Add(lineSegment);
            //if (isHaveLastControlPoint == false)
            //{
            //    lastControlPoint = p1;
            //    isHaveLastControlPoint = true;
            //}
            //LineSegment lineSegment=new LineSegment(p2,true);

            //pathFigure.Segments.Add(lineSegment);
            //            Graphics.FromHwnd(this)
            lastControlPoint = controlPoints[1];
        }
Beispiel #2
0
        private void drawLine(Point p1, Point p2)
        {
            List <Point> controlPoints = BezierHelper.getControlPoints(0.4, p1, p2);

            if (isHaveLastControlPoint == false)
            {
                lastControlPoint       = p1;
                isHaveLastControlPoint = true;
            }
            //先画bezier,再画直线
            //                        QuadraticBezierSegment bezierSegment = new QuadraticBezierSegment(p1, controlPoints[0],  true);
            //
            //                        lastControlPoint = controlPoints[1];
            //                        pathFigure.Segments.Add(bezierSegment);
            //            LineSegment lineSegment = new LineSegment(controlPoints[1], true);
            //            pathFigure.Segments.Add(lineSegment);



            StreamGeometry streamGeometry = new StreamGeometry();

            using (StreamGeometryContext ctx = streamGeometry.Open())
            {
                ctx.BeginFigure(lastControlPoint, false, false);
                ctx.QuadraticBezierTo(p1, controlPoints[0], true, true);
                ctx.LineTo(controlPoints[1], true, true);
            }

            lastControlPoint = controlPoints[1];
            geometryGroup.Children.Add(streamGeometry);
        }
Beispiel #3
0
        private void drawLine(float nCompress, Point p, Point lastTwoPoint, Point lastOnePoint)
        {
            startCount++;
            if (!isStartedPoint)
            {
                startTime             = (DateTime.Now.Ticks - dtFrom.Ticks) / 10000;
                lastControlPoint      = p;
                stylusPointCollection = new StylusPointCollection();
                stylusPointCollection.Add(new StylusPoint(p.X, p.Y, 0.1f));

                stroke = new Stroke(stylusPointCollection);
                stroke.DrawingAttributes = new DrawingAttributes
                {
                    Width = brushWidth, Height = brushWidth, Color = Color.FromRgb(0, 0, 0)
                };
                isStartedPoint = true;
                isFirst        = true;
                ic.Strokes.Add(stroke);
                isHaveLastControlPoint = false;
            }
            else
            {
                isFirst = false;
                if (startCount < 3)
                {
                    stylusPointCollection.Add(new StylusPoint(p.X, p.Y, 0.1f));
                }
                else
                {
                    var controlPoints = BezierHelper.getControlPoints(0.4, lastTwoPoint, lastOnePoint);
                    if (isHaveLastControlPoint && lastControlPoint.X != 0 && lastControlPoint.Y != 0)
                    {
                        var quadraticBezierPoints = BezierHelper.getQuadraticBezierPoints(lastControlPoint,
                                                                                          lastTwoPoint,
                                                                                          controlPoints[0], 6);
                        foreach (var item in quadraticBezierPoints)
                        {
                            stylusPointCollection.Add(new StylusPoint(item.X, item.Y, nCompress));
                        }

                        lastControlPoint = controlPoints[1];
                    }
                    else
                    {
                        isHaveLastControlPoint = true;
                        lastControlPoint       = p;
                        stylusPointCollection.Add(new StylusPoint(p.X, p.Y, nCompress));
                    }
                }

                Console.WriteLine("draw5:{0},{1},{2}", p.X, p.Y, nCompress);
            }
            points.Add(new MyPoint {
                Point = p, Pressure = nCompress, IsFirst = isFirst, LastControlPoint = lastControlPoint
            });
        }
Beispiel #4
0
        private void drawLine2(bool isFrist, float nCompress, Point p, MyPoint lastTwoPoint, MyPoint lastOnePoint)
        {
            if (isFrist)
            {
                Console.WriteLine("isFirst:" + isFrist);
                startTime             = (DateTime.Now.Ticks - dtFrom.Ticks) / 10000;
                lastControlPoint      = p;
                stylusPointCollection = new StylusPointCollection();
                stylusPointCollection.Add(new StylusPoint(p.X, p.Y, 0.1f));

                stroke = new Stroke(stylusPointCollection);
                stroke.DrawingAttributes = new DrawingAttributes
                {
                    Width = brushWidth, Height = brushWidth, Color = Color.FromRgb(0, 0, 0)
                };


                ic.Strokes.Add(stroke);
                isHaveLastControlPoint = false;
            }
            else
            {
                if ((lastTwoPoint.Point.X == 0 && lastTwoPoint.Point.Y == 0) || (lastOnePoint.Point.X == 0 && lastOnePoint.Point.Y == 0))
                {
                    stylusPointCollection.Add(new StylusPoint(p.X, p.Y, 0.1f));
                }
                else
                {
                    var controlPoints = BezierHelper.getControlPoints(0.4, lastTwoPoint.Point, lastOnePoint.Point);
                    if (isHaveLastControlPoint && lastOnePoint.LastControlPoint.X != 0 && lastOnePoint.LastControlPoint.Y != 0)
                    {
                        Console.WriteLine("lastOnePoint.LastControlPoint:" + lastOnePoint.LastControlPoint);
                        var quadraticBezierPoints = BezierHelper.getQuadraticBezierPoints(lastOnePoint.LastControlPoint,
                                                                                          lastTwoPoint.Point,
                                                                                          controlPoints[0], 12);
                        foreach (var item in quadraticBezierPoints)
                        {
                            stylusPointCollection.Add(new StylusPoint(item.X, item.Y, nCompress));
                        }

                        lastControlPoint = controlPoints[1];
                    }
                    else
                    {
                        isHaveLastControlPoint = true;
                        stylusPointCollection.Add(new StylusPoint(p.X, p.Y, nCompress));
                    }
                }

                Console.WriteLine("draw5:{0},{1},{2}", p.X, p.Y, nCompress);
            }
        }
Beispiel #5
0
        private void drawLine(Point p1, Point p2, Point p3)
        {
            List <Point> controlPoints = BezierHelper.getControlPoints(0.3, p1, p2, p3);

            if (isHaveLastControlPoint == false)
            {
                lastControlPoint       = p1;
                isHaveLastControlPoint = true;
            }
            BezierSegment bezierSegment = new BezierSegment(lastControlPoint, controlPoints[0], p2, true);

            lastControlPoint = controlPoints[1];
            pathFigure.Segments.Add(bezierSegment);
        }
Beispiel #6
0
        private void initViews()
        {
            PathGeometry pathGeometry = new PathGeometry();

            pathFigure = new PathFigure();
            pathGeometry.Figures.Add(pathFigure);
            Point p1 = new Point(100, 300);
            Point p2 = new Point(200, 200);
            Point p3 = new Point(300, 300);
            Point p4 = new Point(400, 300);

//            List<Point> controlPoints = getControlPoints(0.3, p1, p2, p3);

            pathFigure.StartPoint = p1;

//            BezierSegment bezierSegment=new BezierSegment(p1,controlPoints[0],p2,true);
//            pathFigure.Segments.Add(bezierSegment);
//            Point lastControlPoint = controlPoints[1];
//
//            controlPoints = getControlPoints(0.3, p2, p3, p4); ;
//            bezierSegment = new BezierSegment(lastControlPoint, controlPoints[0], p3, true);
//
//            pathFigure.Segments.Add(bezierSegment);


            List <Point> controlPoints = BezierHelper.getControlPoints(0.4, p1, p2);

            pathFigure.StartPoint = p1;
            LineSegment lineSegment = new LineSegment(controlPoints[0], true);

            pathFigure.Segments.Add(lineSegment);

            controlPoints = BezierHelper.getControlPoints(0.4, p2, p3);
            QuadraticBezierSegment bezierSegment = new QuadraticBezierSegment(p2, controlPoints[0], true);

            pathFigure.Segments.Add(bezierSegment);

            lineSegment = new LineSegment(controlPoints[1], true);
            pathFigure.Segments.Add(lineSegment);

            controlPoints = BezierHelper.getControlPoints(0.4, p3, p4);
            bezierSegment = new QuadraticBezierSegment(p3, controlPoints[0], true);
            pathFigure.Segments.Add(bezierSegment);

            Path path = new Path();

            path.Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            path.Data   = pathGeometry;
            canvas.Children.Add(path);
        }