프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / MarkupToPDF / Controls / Common / InkToPath.cs @ f959ea6f

이력 | 보기 | 이력해설 | 다운로드 (4.25 KB)

1
using MarkupToPDF.Controls.Polygon;
2
using System;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7
using System.Windows;
8
using System.Windows.Ink;
9
using System.Windows.Input;
10
using System.Windows.Media;
11
using System.Windows.Shapes;
12

    
13
namespace MarkupToPDF.Controls.Common
14
{
15
    public class InkToPath
16
    {
17
        public double[,] StrokeGetPoints(Stroke oStroke)
18
        {
19
            int iRow = -1;
20
            System.Windows.Input.StylusPointCollection colStylusPoints =
21
                                                  oStroke.StylusPoints;
22
            double[,] AllPoints = new double[colStylusPoints.Count, 2];
23
            foreach (StylusPoint oPoint in colStylusPoints)
24
            {
25
                iRow += 1;
26
                AllPoints[iRow, 0] = oPoint.X;
27
                AllPoints[iRow, 1] = oPoint.Y;
28
            }
29
            return AllPoints;
30
        }
31

    
32
        /// <summary>
33
        /// get points form a stroke
34
        /// </summary>
35
        /// <param name="oStroke"></param>
36
        /// <returns></returns>
37
        public List<Point> GetPointsFrom(Stroke oStroke)
38
        {
39
            System.Windows.Input.StylusPointCollection colStylusPoints =
40
                                      oStroke.StylusPoints;
41

    
42
            List<Point> instance = new List<Point>();
43
            foreach (StylusPoint oPoint in colStylusPoints)
44
            {
45
                instance.Add(new Point(oPoint.X, oPoint.Y));
46
            }
47
            return instance;
48
        }
49

    
50
        public StrokeCollection PointGetStroke(List<Point> lstPoint, double lineSize)
51
        {
52
            //foreach (var T in _InkBoard.Strokes[i].StylusPoints) 참고
53
            StrokeCollection strokeSet = new StrokeCollection();
54

    
55

    
56
            Stroke instance = new Stroke(null);
57
            instance.DrawingAttributes.Color = Colors.Red;
58
            instance.DrawingAttributes.Width = lineSize;
59
            instance.DrawingAttributes.Height = lineSize;
60

    
61
            foreach (var data in lstPoint)
62
            {
63
                instance.StylusPoints.Add(new StylusPoint { X = data.X, Y = data.Y, PressureFactor = 0.5F });
64
               
65

    
66
                strokeSet.Add(instance);
67
            }
68

    
69
            return strokeSet;
70
        }
71

    
72
        public Path StrokeToPath(Stroke oStroke)
73
        {
74
            PathFigure myPathFigure = null;
75
            LineSegment myLineSegment = null;
76
            PathFigureCollection myPathFigureCollection =
77
                new PathFigureCollection();
78
            PathSegmentCollection myPathSegmentCollection =
79
                new PathSegmentCollection();
80

    
81
            if (oStroke == null) return null;
82

    
83
            // Number of points.
84
            int n = oStroke.StylusPoints.Count;
85
            if (n == 0) return null;
86

    
87
            // Start point is first point from sytluspoints collection (M, item 0).
88
            myPathFigure = new PathFigure();
89
            myPathFigure.StartPoint =
90
                new Point(oStroke.StylusPoints[0].X, oStroke.StylusPoints[0].Y);
91
            myPathFigureCollection.Add(myPathFigure);
92

    
93
            // Make small line segment L if there is only one point in the Stroke.
94
            // Data with only M is not shown (workaround).
95
            if (n == 1)
96
            {
97
                myLineSegment = new LineSegment();
98
                myLineSegment.Point =
99
                    new Point(oStroke.StylusPoints[0].X + 1,
100
                              oStroke.StylusPoints[0].Y + 1);
101
                myPathSegmentCollection.Add(myLineSegment);
102
            }
103

    
104
            // The other points are line segments (L, items 1..n-1).
105
            for (int i = 1; i < n; i++)
106
            {
107
                myLineSegment = new LineSegment();
108
                myLineSegment.Point =
109
                    new Point(oStroke.StylusPoints[i].X,
110
                              oStroke.StylusPoints[i].Y);
111
                myPathSegmentCollection.Add(myLineSegment);
112
            }
113

    
114
            myPathFigure.Segments = myPathSegmentCollection;
115

    
116
            PathGeometry myPathGeometry = new PathGeometry();
117
            myPathGeometry.Figures = myPathFigureCollection;
118

    
119
            System.Windows.Shapes.Path oPath = new System.Windows.Shapes.Path();
120

    
121
            // Add the data to the Path.
122
            oPath.Data = myPathGeometry;
123

    
124
            return oPath;
125
        }
126
    }
127
}
클립보드 이미지 추가 (최대 크기: 500 MB)