Пример #1
0
        void RenderStroke(InkStroke inkStroke)
        {
            Brush brush = new SolidColorBrush(inkStroke.DrawingAttributes.Color);
            IReadOnlyList <InkStrokeRenderingSegment> inkSegments = inkStroke.GetRenderingSegments();

            for (int i = 1; i < inkSegments.Count; i++)
            {
                InkStrokeRenderingSegment inkSegment    = inkSegments[i];
                BezierSegment             bezierSegment = new BezierSegment
                {
                    Point1 = inkSegment.BezierControlPoint1,
                    Point2 = inkSegment.BezierControlPoint2,
                    Point3 = inkSegment.Position
                };
                PathFigure pathFigure = new PathFigure
                {
                    StartPoint = inkSegments[i - 1].Position,
                    IsClosed   = false,
                    IsFilled   = false
                };
                pathFigure.Segments.Add(bezierSegment);
                PathGeometry pathGeometry = new PathGeometry();
                pathGeometry.Figures.Add(pathFigure);
                Path path = new Path
                {
                    Stroke             = brush,
                    StrokeThickness    = inkStroke.DrawingAttributes.Size.Width,// * inkSegment.Pressure,
                    StrokeStartLineCap = PenLineCap.Round,
                    StrokeEndLineCap   = PenLineCap.Round,
                    Data = pathGeometry
                };
                StrokeGrid.Children.Add(path);
            }
        }
Пример #2
0
        /// <summary>
        /// A private helper method used to produce BezierPaths from InkStorkes
        /// </summary>
        /// <param name="stroke">The InkStroke used to render the permanent ink</param>
        /// <param name="drawAttr">The InkDrawingAttributes used to render the permanent ink</param>
        /// <returns>A new Path built from BezierSegments</returns>
        private Path ProduceBezierPath(InkStroke stroke, InkDrawingAttributes drawAttr)
        {
            //Create a new PathFeagure instance
            PathFigure figure = new PathFigure();
            //Get all of the InkStroke's rendering segments
            IReadOnlyList <InkStrokeRenderingSegment> curveSegments = stroke.GetRenderingSegments();

            //Check if we have any segments to work with
            if (curveSegments.Count > 0)
            {
                //Use the first segment to set the figure's start position
                figure.StartPoint = curveSegments[0].Position;
            }
            //Iterate over the segment collection, beginning from the 2nd element
            for (int i = 1; i < curveSegments.Count; ++i)
            {
                //Get an InkStrokeRenderingSegemnt instance from the collection
                InkStrokeRenderingSegment pathSegment = curveSegments[i];
                //Create a new BezierSegment instance
                BezierSegment segment = new BezierSegment();
                //Set the segment's control points
                segment.Point1 = pathSegment.BezierControlPoint1;
                segment.Point2 = pathSegment.BezierControlPoint2;
                //Set the segment's position
                segment.Point3 = pathSegment.Position;
                //Add the new segment to the figure
                figure.Segments.Add(segment);
            }

            //Create a new Path instance
            Path path = new Path();

            //Populate the path's data with a new PathGeometry instancce
            path.Data = new PathGeometry();
            //Add the figure instance to the new PathGeometry
            (path.Data as PathGeometry).Figures.Add(figure);

            //Set the path's stroke color to the drawAttr's color
            path.Stroke = new SolidColorBrush(drawAttr.Color);
            //Set the path's stroke thickness to the drawAttr's Width
            path.StrokeThickness = drawAttr.Size.Width;
            //Set the path's stroke line join to best fit the drawAttr's pen tip
            path.StrokeLineJoin = drawAttr.PenTip == PenTipShape.Circle ? Windows.UI.Xaml.Media.PenLineJoin.Round
                                                                        : Windows.UI.Xaml.Media.PenLineJoin.Miter;
            //Set the path's stroke line cap to best fit the drawAttr's pen tip
            path.StrokeStartLineCap = drawAttr.PenTip == PenTipShape.Circle ? Windows.UI.Xaml.Media.PenLineCap.Round
                                                                            : Windows.UI.Xaml.Media.PenLineCap.Square;
            //Return the new path
            return(path);
        }
Пример #3
0
        void RenderStroke(InkStroke inkStroke)
        {
            Brush brush = new SolidColorBrush(inkStroke.DrawingAttributes.Color);
            IReadOnlyList <InkStrokeRenderingSegment> inkSegments = inkStroke.GetRenderingSegments();

            for (int i = 1; i < inkSegments.Count; i++)
            {
                InkStrokeRenderingSegment inkSegment    = inkSegments[i];
                BezierSegment             bezierSegment = new BezierSegment
                {
                    Point1 = inkSegment.BezierControlPoint1,
                    Point2 = inkSegment.BezierControlPoint2,
                    Point3 = inkSegment.Position
                };
                PathFigure pathFigure = new PathFigure
                {
                    StartPoint = inkSegments[i - 1].Position,
                    IsClosed   = false,
                    IsFilled   = false
                };
                pathFigure.Segments.Add(bezierSegment);
                PathGeometry pathGeometry = new PathGeometry();
                pathGeometry.Figures.Add(pathFigure);
                Path path = new Path
                {
                    Stroke             = brush,
                    StrokeThickness    = inkStroke.DrawingAttributes.Size.Width,// * inkSegment.Pressure,
                    StrokeStartLineCap = PenLineCap.Round,
                    StrokeEndLineCap   = PenLineCap.Round,
                    Data = pathGeometry
                };
                StrokeGrid.Children.Add(path);

#if DEBUG
                Ellipse el = new Ellipse()
                {
                    Width            = 10,
                    Height           = 10,
                    Fill             = new SolidColorBrush(Color.FromArgb(200, 0, 0, 0)),
                    IsHitTestVisible = false
                };

                Canvas.SetLeft(el, inkSegment.Position.X - 5);
                Canvas.SetTop(el, inkSegment.Position.Y - 5);
                //TestCanvas.Children.Add(el);
#endif
            }
        }
        static void RenderBeziers(Panel panel, InkStroke inkStroke, Color color, double penSize)
        {
            Brush brush = new SolidColorBrush(color);
            IReadOnlyList <InkStrokeRenderingSegment> inkSegments = inkStroke.GetRenderingSegments();

            for (int i = 1; i < inkSegments.Count; i++)
            {
                InkStrokeRenderingSegment inkSegment = inkSegments[i];

                BezierSegment bezierSegment = new BezierSegment
                {
                    Point1 = inkSegment.BezierControlPoint1,
                    Point2 = inkSegment.BezierControlPoint2,
                    Point3 = inkSegment.Position
                };

                PathFigure pathFigure = new PathFigure
                {
                    StartPoint = inkSegments[i - 1].Position,
                    IsClosed   = false,
                    IsFilled   = false
                };
                pathFigure.Segments.Add(bezierSegment);

                PathGeometry pathGeometry = new PathGeometry();
                pathGeometry.Figures.Add(pathFigure);

                Path path = new Path
                {
                    Stroke             = brush,
                    StrokeThickness    = penSize * inkSegment.Pressure,
                    StrokeStartLineCap = PenLineCap.Round,
                    StrokeEndLineCap   = PenLineCap.Round,
                    Data = pathGeometry
                };
                panel.Children.Add(path);
            }
        }
        protected override void OnPointerReleased(PointerRoutedEventArgs args)
        {
            if (args.Pointer.PointerDeviceType != PointerDeviceType.Pen && hasPen)
            {
                return;
            }

            inkManager.ProcessPointerUp(args.GetCurrentPoint(this));

            // Render the most recent InkStroke
            IReadOnlyList <InkStroke> inkStrokes = inkManager.GetStrokes();
            InkStroke inkStroke = inkStrokes[inkStrokes.Count - 1];

            // Create SolidColorBrush used for all segments in the stroke
            Brush brush = new SolidColorBrush(inkStroke.DrawingAttributes.Color);

            // Get the segments
            IReadOnlyList <InkStrokeRenderingSegment> inkSegments = inkStroke.GetRenderingSegments();

            // Notice loop starts at 1
            for (int i = 1; i < inkSegments.Count; i++)
            {
                InkStrokeRenderingSegment inkSegment = inkSegments[i];

                // Create a BezierSegment from the points
                BezierSegment bezierSegment = new BezierSegment
                {
                    Point1 = inkSegment.BezierControlPoint1,
                    Point2 = inkSegment.BezierControlPoint2,
                    Point3 = inkSegment.Position
                };

                // Create a PathFigure that begins at the preceding Position
                PathFigure pathFigure = new PathFigure
                {
                    StartPoint = inkSegments[i - 1].Position,
                    IsClosed   = false,
                    IsFilled   = false
                };
                pathFigure.Segments.Add(bezierSegment);

                // Create a PathGeometry with that PathFigure
                PathGeometry pathGeometry = new PathGeometry();
                pathGeometry.Figures.Add(pathFigure);

                // Create a Path with that PathGeometry
                Path path = new Path
                {
                    Stroke          = brush,
                    StrokeThickness = inkStroke.DrawingAttributes.Size.Width *
                                      inkSegment.Pressure,
                    StrokeStartLineCap = PenLineCap.Round,
                    StrokeEndLineCap   = PenLineCap.Round,
                    Data = pathGeometry
                };

                // Add it to the Grid
                contentGrid.Children.Add(path);
            }
            base.OnPointerReleased(args);
        }