프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Common / InkToPath.cs @ 684ef11c

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

1 787a4489 KangIngu
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.Windows;
7
using System.Windows.Ink;
8
using System.Windows.Input;
9
using System.Windows.Media;
10
using System.Windows.Shapes;
11
12
namespace MarkupToPDF.Controls.Common
13
{
14
    public class InkToPath
15
    {
16
        public double[,] StrokeGetPoints(Stroke oStroke)
17
        {
18
            int iRow = -1;
19
            System.Windows.Input.StylusPointCollection colStylusPoints =
20
                                                  oStroke.StylusPoints;
21
            double[,] AllPoints = new double[colStylusPoints.Count, 2];
22
            foreach (StylusPoint oPoint in colStylusPoints)
23
            {
24
                iRow += 1;
25
                AllPoints[iRow, 0] = oPoint.X;
26
                AllPoints[iRow, 1] = oPoint.Y;
27
            }
28
            return AllPoints;
29
        }
30
31
        public List<Point> StrokeGetPointsPlus(Stroke oStroke)
32
        {
33
            System.Windows.Input.StylusPointCollection colStylusPoints =
34
                                      oStroke.StylusPoints;
35
36
            List<Point> instance = new List<Point>();
37
            foreach (StylusPoint oPoint in colStylusPoints)
38
            {
39
                instance.Add(new Point(oPoint.X, oPoint.Y));
40
            }
41
            return instance;
42
        }
43
44
        public StrokeCollection PointGetStroke(List<Point> lstPoint, double lineSize)
45
        {
46
            //foreach (var T in _InkBoard.Strokes[i].StylusPoints) 참고
47
            StrokeCollection strokeSet = new StrokeCollection();
48
49
50
            Stroke instance = new Stroke(null);
51
            instance.DrawingAttributes.Color = Colors.Red;
52
            instance.DrawingAttributes.Width = lineSize;
53
            instance.DrawingAttributes.Height = lineSize;
54
55
            foreach (var data in lstPoint)
56
            {
57
                instance.StylusPoints.Add(new StylusPoint { X = data.X, Y = data.Y, PressureFactor = 0.5F });
58
               
59
60
                strokeSet.Add(instance);
61
            }
62
63
            return strokeSet;
64
        }
65
66
        public Path StrokeToPath(Stroke oStroke)
67
        {
68
            PathFigure myPathFigure = null;
69
            LineSegment myLineSegment = null;
70
            PathFigureCollection myPathFigureCollection =
71
                new PathFigureCollection();
72
            PathSegmentCollection myPathSegmentCollection =
73
                new PathSegmentCollection();
74
75
            if (oStroke == null) return null;
76
77
            // Number of points.
78
            int n = oStroke.StylusPoints.Count;
79
            if (n == 0) return null;
80
81
            // Start point is first point from sytluspoints collection (M, item 0).
82
            myPathFigure = new PathFigure();
83
            myPathFigure.StartPoint =
84
                new Point(oStroke.StylusPoints[0].X, oStroke.StylusPoints[0].Y);
85
            myPathFigureCollection.Add(myPathFigure);
86
87
            // Make small line segment L if there is only one point in the Stroke.
88
            // Data with only M is not shown (workaround).
89
            if (n == 1)
90
            {
91
                myLineSegment = new LineSegment();
92
                myLineSegment.Point =
93
                    new Point(oStroke.StylusPoints[0].X + 1,
94
                              oStroke.StylusPoints[0].Y + 1);
95
                myPathSegmentCollection.Add(myLineSegment);
96
            }
97
98
            // The other points are line segments (L, items 1..n-1).
99
            for (int i = 1; i < n; i++)
100
            {
101
                myLineSegment = new LineSegment();
102
                myLineSegment.Point =
103
                    new Point(oStroke.StylusPoints[i].X,
104
                              oStroke.StylusPoints[i].Y);
105
                myPathSegmentCollection.Add(myLineSegment);
106
            }
107
108
            myPathFigure.Segments = myPathSegmentCollection;
109
110
            PathGeometry myPathGeometry = new PathGeometry();
111
            myPathGeometry.Figures = myPathFigureCollection;
112
113
            System.Windows.Shapes.Path oPath = new System.Windows.Shapes.Path();
114
115
            // Add the data to the Path.
116
            oPath.Data = myPathGeometry;
117
118
            return oPath;
119
        }
120
121
    }
122
}
클립보드 이미지 추가 (최대 크기: 500 MB)