markus / MarkupToPDF_Old / Controls / Common / InkToPath.cs @ 9fa712a5
이력 | 보기 | 이력해설 | 다운로드 (4.16 KB)
1 |
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 |
#if SILVERLIGHT |
49 |
Stroke instance = new Stroke(); |
50 |
#endif |
51 |
#if !SILVERLIGHT |
52 |
Stroke instance = new Stroke(null); |
53 |
#endif |
54 |
instance.DrawingAttributes.Color = Colors.Red; |
55 |
instance.DrawingAttributes.Width = lineSize; |
56 |
instance.DrawingAttributes.Height = lineSize; |
57 |
|
58 |
foreach (var data in lstPoint) |
59 |
{ |
60 |
instance.StylusPoints.Add(new StylusPoint { X = data.X, Y = data.Y, PressureFactor = 0.5F }); |
61 |
|
62 |
|
63 |
strokeSet.Add(instance); |
64 |
} |
65 |
|
66 |
return strokeSet; |
67 |
} |
68 |
|
69 |
public Path StrokeToPath(Stroke oStroke) |
70 |
{ |
71 |
PathFigure myPathFigure = null; |
72 |
LineSegment myLineSegment = null; |
73 |
PathFigureCollection myPathFigureCollection = |
74 |
new PathFigureCollection(); |
75 |
PathSegmentCollection myPathSegmentCollection = |
76 |
new PathSegmentCollection(); |
77 |
|
78 |
if (oStroke == null) return null; |
79 |
|
80 |
// Number of points. |
81 |
int n = oStroke.StylusPoints.Count; |
82 |
if (n == 0) return null; |
83 |
|
84 |
// Start point is first point from sytluspoints collection (M, item 0). |
85 |
myPathFigure = new PathFigure(); |
86 |
myPathFigure.StartPoint = |
87 |
new Point(oStroke.StylusPoints[0].X, oStroke.StylusPoints[0].Y); |
88 |
myPathFigureCollection.Add(myPathFigure); |
89 |
|
90 |
// Make small line segment L if there is only one point in the Stroke. |
91 |
// Data with only M is not shown (workaround). |
92 |
if (n == 1) |
93 |
{ |
94 |
myLineSegment = new LineSegment(); |
95 |
myLineSegment.Point = |
96 |
new Point(oStroke.StylusPoints[0].X + 1, |
97 |
oStroke.StylusPoints[0].Y + 1); |
98 |
myPathSegmentCollection.Add(myLineSegment); |
99 |
} |
100 |
|
101 |
// The other points are line segments (L, items 1..n-1). |
102 |
for (int i = 1; i < n; i++) |
103 |
{ |
104 |
myLineSegment = new LineSegment(); |
105 |
myLineSegment.Point = |
106 |
new Point(oStroke.StylusPoints[i].X, |
107 |
oStroke.StylusPoints[i].Y); |
108 |
myPathSegmentCollection.Add(myLineSegment); |
109 |
} |
110 |
|
111 |
myPathFigure.Segments = myPathSegmentCollection; |
112 |
|
113 |
PathGeometry myPathGeometry = new PathGeometry(); |
114 |
myPathGeometry.Figures = myPathFigureCollection; |
115 |
|
116 |
System.Windows.Shapes.Path oPath = new System.Windows.Shapes.Path(); |
117 |
|
118 |
// Add the data to the Path. |
119 |
oPath.Data = myPathGeometry; |
120 |
|
121 |
return oPath; |
122 |
} |
123 |
|
124 |
} |
125 |
} |