프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Etc / ImgControl.cs @ 26c9c3bf

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

1 787a4489 KangIngu
using System;
2
using System.Net;
3
using System.Windows;
4
using System.Windows.Controls;
5
using System.Windows.Documents;
6
using System.Windows.Ink;
7
using System.Windows.Input;
8
using System.Windows.Media;
9
using System.Windows.Media.Animation;
10
using System.Windows.Shapes;
11
using System.Collections.Generic;
12
using System.ComponentModel;
13
using System.Linq;
14
using MarkupToPDF.Controls.Common;
15
using MarkupToPDF.Common;
16 036650a0 humkyung
using MarkupToPDF.Serialize.Core;
17
using MarkupToPDF.Serialize.S_Control;
18 661b7416 humkyung
using System.Windows.Media.Imaging;
19 7b34fb3a swate0609
using MarkupToPDF.Controls.Shape;
20
using System.Security.Policy;
21 787a4489 KangIngu
22
namespace MarkupToPDF.Controls.Etc
23
{
24 9005f973 humkyung
    [TemplatePart(Name = "PART_Image", Type = typeof(Image))]
25 787a4489 KangIngu
    public class ImgControl : CommentUserInfo, IDisposable, INormal, INotifyPropertyChanged, IViewBox, IMarkupCommonData
26
    {
27
        #region 초기선언
28
        private const string PART_Image = "PART_Image";
29
        public Image Base_Image = null;
30
        #endregion
31
32
        static ImgControl()
33
        {
34
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ImgControl), new FrameworkPropertyMetadata(typeof(ImgControl)));
35
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
36 a6f7f9b6 djkim
            //ResourceDictionary dictionary = new ResourceDictionary();
37
            //dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
38
            //Application.Current.Resources.MergedDictionaries.Add(dictionary);
39 787a4489 KangIngu
             //System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count);
40
        }
41
42
        public ImgControl()
43
        {
44 a6f7f9b6 djkim
            //this.DefaultStyleKey = typeof(ImgControl);
45 787a4489 KangIngu
        }
46 7b34fb3a swate0609
        public override void Copy(CommentUserInfo lhs)
47
        {
48
            if(lhs is ImgControl imgControl)
49
            {
50
                this.CommentAngle = imgControl.CommentAngle;
51
                this.StartPoint = new Point(imgControl.StartPoint.X, imgControl.StartPoint.Y);
52
                this.TopRightPoint = new Point(imgControl.TopRightPoint.X, imgControl.TopRightPoint.Y);
53
                this.EndPoint = new Point(imgControl.EndPoint.X, imgControl.EndPoint.Y);
54
                this.LeftBottomPoint = new Point(imgControl.LeftBottomPoint.X, imgControl.LeftBottomPoint.Y);
55
                this.PointSet = imgControl.PointSet.ConvertAll(x => new Point(x.X, x.Y));
56
                this.Opacity = imgControl.Opacity;
57
                this.FilePath = imgControl.FilePath;
58
                this.UserID = imgControl.UserID;
59
                this.ImageData = imgControl.ImageData;
60
                this.Memo = imgControl.Memo;
61 b2d0f316 humkyung
                this.ZIndex = imgControl.ZIndex;
62 7b34fb3a swate0609
            }
63
        }
64
65
        public override CommentUserInfo Clone()
66
        {
67
            var clone = new ImgControl();
68
            clone.Copy(this);
69
            return clone;
70
        }
71 787a4489 KangIngu
72
        public void Dispose()
73
        {
74 a6f7f9b6 djkim
            //GC.Collect();
75 24c5e56c taeseongkim
            ////GC.SuppressFinalize(this);
76 a6f7f9b6 djkim
            this.Base_Image = null;
77 787a4489 KangIngu
        }
78
        public event PropertyChangedEventHandler PropertyChanged;
79
        protected void OnPropertyChanged(string propName)
80
        {
81
            if (PropertyChanged != null)
82
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
83
        }
84
85 f513c215 humkyung
        public override void ApplyOverViewData()
86 787a4489 KangIngu
        {
87
            this.OverViewPathData = this.PathData;
88
        }
89
90
        #region Dependency Properties
91
92
        public static readonly DependencyProperty IsSelectedProperty =
93
            DependencyProperty.Register("IsSelected", typeof(bool), typeof(ImgControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
94
95
        public static readonly DependencyProperty ControlTypeProperty =
96
            DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ImgControl), new FrameworkPropertyMetadata(ControlType.ImgControl));
97
98 53880c83 ljiyeon
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
99
       "PathData", typeof(Geometry), typeof(ImgControl), null);
100 787a4489 KangIngu
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
101
        "OverViewPathData", typeof(Geometry), typeof(ImgControl), null);
102
103
        public static readonly DependencyProperty ImageDataProperty = DependencyProperty.Register(
104
            "ImageData", typeof(ImageSource), typeof(ImgControl), new PropertyMetadata(null));
105
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
106
            "UserID", typeof(string), typeof(ImgControl), new PropertyMetadata(null));
107
        public static readonly DependencyProperty FilePathProperty = DependencyProperty.Register(
108
            "FilePath", typeof(string), typeof(ImgControl), new PropertyMetadata(null));
109
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
110
            "StartPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
111
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
112
            "EndPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
113
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
114
            "PointSet", typeof(List<Point>), typeof(ImgControl), new PropertyMetadata(new List<Point>()));
115
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
116
             "TopRightPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
117
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
118
              "LeftBottomPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
119
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(ImgControl),
120
                        new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
121
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(ImgControl),
122
                        new PropertyMetadata((double)0, OnCenterXYChanged));
123
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(ImgControl),
124
                        new PropertyMetadata((double)0, OnCenterXYChanged));
125
126
        #endregion
127
        #region PropertyChanged Method
128
129
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
130
        {
131
            //var instance = (ImgControl)sender;
132
133
            //if (e.OldValue != e.NewValue && instance.Base_Image != null)
134
            //{
135
136
            //    instance.SetValue(e.Property, e.NewValue);
137
138
            //    if (instance.IsSelected)
139
            //    {
140
            //        //instance.Base_Image.Stroke = new SolidColorBrush(Colors.Blue);
141
            //    }
142
            //    else
143
            //    {
144
            //        //instance.Base_Image.Stroke = new SolidColorBrush(Colors.Red);
145
            //    }
146
            //}
147
        }
148
149
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
150
        {
151
            var instance = (ImgControl)sender;
152
            if (e.OldValue != e.NewValue && instance.Base_Image != null)
153
            {
154
                instance.SetValue(e.Property, e.NewValue);
155
                instance.SetImage();
156
            }
157
        }
158
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
159
        {
160
            var instance = (ImgControl)sender;
161
            if (e.OldValue != e.NewValue && instance.Base_Image != null)
162
            {
163
                instance.SetValue(e.Property, e.NewValue);
164
                instance.SetImage();
165
            }
166
        }
167
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
168
        {
169
            var instance = (ImgControl)sender;
170
            if (e.OldValue != e.NewValue && instance.Base_Image != null)
171
            {
172
                instance.SetValue(e.Property, e.NewValue);
173
                instance.SetImage();
174
            }
175
        }
176
        #endregion
177
        #region Properties
178
        public double CenterX
179
        {
180
            get { return (double)GetValue(CenterXProperty); }
181
            set { SetValue(CenterXProperty, value); }
182
        }
183
        public string UserID
184
        {
185
            get { return (string)GetValue(UserIDProperty); }
186
            set
187
            {
188
                if (this.UserID != value)
189
                {
190
                    SetValue(UserIDProperty, value);
191
                    OnPropertyChanged("UserID");
192
                }
193
            }
194
        }
195
       
196
        public double CenterY
197
        {
198
            get { return (double)GetValue(CenterYProperty); }
199
            set { SetValue(CenterYProperty, value); }
200
        }
201
        public string FilePath
202
        {
203
            get { return (string)GetValue(FilePathProperty); }
204
            set { SetValue(FilePathProperty, value); }
205
        }
206
        public Point EndPoint
207
        {
208
            get { return (Point)GetValue(EndPointProperty); }
209
            set
210
            {
211
                if (this.EndPoint != value)
212
                {
213
                    SetValue(EndPointProperty, value);
214
                    OnPropertyChanged("EndPoint");
215
                }
216
            }
217
        }
218
        public List<Point> PointSet
219
        {
220
            get { return (List<Point>)GetValue(PointSetProperty); }
221
            set { SetValue(PointSetProperty, value); }
222
        }
223
        public Point StartPoint
224
        {
225
            get { return (Point)GetValue(StartPointProperty); }
226
            set
227
            {
228
                if (this.StartPoint != value)
229
                {
230
                    SetValue(StartPointProperty, value);
231
                    OnPropertyChanged("StartPoint");
232
                }
233
            }
234
        }
235
        public Point TopRightPoint
236
        {
237
            get { return (Point)GetValue(TopRightPointProperty); }
238
            set
239
            {
240
                SetValue(TopRightPointProperty, value);
241
                OnPropertyChanged("TopRightPoint");
242
            }
243
        }
244
        public Point LeftBottomPoint
245
        {
246
            get { return (Point)GetValue(LeftBottomPointProperty); }
247
            set
248
            {
249
                SetValue(LeftBottomPointProperty, value);
250
                OnPropertyChanged("LeftBottomPoint");
251
            }
252
        }
253 554aae3b humkyung
254 fa48eb85 taeseongkim
        public override double CommentAngle
255 787a4489 KangIngu
        {
256
            get { return (double)GetValue(AngleProperty); }
257
            set
258
            {
259 fa48eb85 taeseongkim
                if (this.CommentAngle != value)
260 787a4489 KangIngu
                {
261
                    SetValue(AngleProperty, value);
262
                }
263
            }
264
        }
265
        public ImageSource ImageData
266
        {
267
            get { return (ImageSource)this.GetValue(ImageDataProperty); }
268
            set { this.SetValue(ImageDataProperty, value); }
269
        }
270
271 959b3ef2 humkyung
         public override bool IsSelected
272 787a4489 KangIngu
        {
273
            get
274
            {
275
                return (bool)GetValue(IsSelectedProperty);
276
            }
277
            set
278
            {
279
                SetValue(IsSelectedProperty, value);
280 53880c83 ljiyeon
                //OnPropertyChanged("IsSelected");
281 787a4489 KangIngu
            }
282
        }
283
284 5529d2a2 humkyung
        public override ControlType ControlType
285 787a4489 KangIngu
        {
286
            set
287
            {
288
                SetValue(ControlTypeProperty, value);
289
                OnPropertyChanged("ControlType");
290
            }
291
            get
292
            {
293
                return (ControlType)GetValue(ControlTypeProperty);
294
            }
295
        }
296
297
        public Geometry OverViewPathData
298
        {
299
            get { return (Geometry)GetValue(OverViewPathDataProperty); }
300
            set
301
            {
302
                SetValue(OverViewPathDataProperty, value);
303
                OnPropertyChanged("OverViewPathData");
304
            }
305
        }
306
307
308
        #endregion
309
310
        public override void OnApplyTemplate()
311
        {
312
            base.OnApplyTemplate();
313
            Base_Image = GetTemplateChild(PART_Image) as Image;
314
            Base_Image.Width = 0;
315
            Base_Image.Height = 0;
316
            SetImage();
317
        }
318 661b7416 humkyung
319 787a4489 KangIngu
        public void SetImage()
320
        {
321
            this.ApplyTemplate();
322
            Point mid = MathSet.FindCentroid(new List<Point>()
323
            {
324
                this.StartPoint,
325
                this.LeftBottomPoint,
326
                this.EndPoint,
327
                this.TopRightPoint,                
328
            });
329 fa48eb85 taeseongkim
            double AngleData = this.CommentAngle * -1;
330 787a4489 KangIngu
            PathFigure pathFigure = new PathFigure();
331
332
            pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
333
334
            LineSegment lineSegment0 = new LineSegment();
335
            lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
336
            pathFigure.Segments.Add(lineSegment0);
337
338
            LineSegment lineSegment1 = new LineSegment();
339
            lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData);
340
            pathFigure.Segments.Add(lineSegment1);
341
342
            LineSegment lineSegment2 = new LineSegment();
343
            lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData);
344
            pathFigure.Segments.Add(lineSegment2);
345
346
            LineSegment lineSegment3 = new LineSegment();
347
            lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData);
348
            pathFigure.Segments.Add(lineSegment3);
349
350
            PathGeometry pathGeometry = new PathGeometry();
351
            pathGeometry.Figures = new PathFigureCollection();
352
            pathFigure.IsClosed = true;
353
            pathGeometry.Figures.Add(pathFigure);
354
            this.Base_Image.Width = pathGeometry.Bounds.Width;
355
            this.Base_Image.Height = pathGeometry.Bounds.Height;
356
             this.Tag = pathGeometry;
357
358
            Canvas.SetLeft(this, MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_Image.Width / 2);
359
            Canvas.SetTop(this, MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_Image.Height / 2);
360
361 53880c83 ljiyeon
            this.PathData = pathGeometry;
362
            ApplyOverViewData();
363
364 787a4489 KangIngu
        }
365 0d00f9c8 humkyung
        public override void UpdateControl()
366 787a4489 KangIngu
        {
367
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
368
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
369
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
370
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
371
        }
372
373
        public double LineSize { get; set; }
374
375 53880c83 ljiyeon
        public Geometry PathData { get; set; }
376 90e7968d ljiyeon
377 036650a0 humkyung
        /// <summary>
378 a6272c57 humkyung
        /// call when mouse is moving while drawing control
379
        /// </summary>
380
        /// <param name="pt"></param>
381
        /// <param name="bAxisLocked"></param>
382 233ef333 taeseongkim
        public override void OnCreatingMouseMove(Point pt, bool bAxisLocked)
383 a6272c57 humkyung
        {
384 49a6d7c3 humkyung
            if (bAxisLocked)
385
            {
386
                double _dx = pt.X - this.StartPoint.X;
387
                double _dy = pt.Y - this.StartPoint.Y;
388
                double dist = Math.Max(Math.Abs(_dx), Math.Abs(_dy));
389
                var dir = new Vector(_dx, _dy);
390
                dir.Normalize();
391
392
                this.LeftBottomPoint = new Point(this.StartPoint.X, this.StartPoint.Y + (dir.Y > 0 ? 1 : -1) * dist);
393
                this.TopRightPoint = new Point(this.StartPoint.X + (dir.X > 0 ? 1 : -1) * dist, this.StartPoint.Y);
394
                this.EndPoint = new Point(this.TopRightPoint.X, this.LeftBottomPoint.Y);
395
            }
396
            else
397
            {
398
                this.EndPoint = pt;
399
                this.LeftBottomPoint = new Point(this.StartPoint.X, this.EndPoint.Y);
400
                this.TopRightPoint = new Point(this.EndPoint.X, this.StartPoint.Y);
401
            }
402 a6272c57 humkyung
            
403
            this.PointSet = new List<Point>
404
            {
405
                this.StartPoint,
406
                this.LeftBottomPoint,
407
                this.EndPoint,
408
                this.TopRightPoint,
409
            };
410
        }
411
412
        /// <summary>
413 d2114d3b humkyung
        /// move control point has same location of given pt along given delta
414
        /// </summary>
415
        /// <author>humkyung</author>
416
        /// <date>2019.06.20</date>
417
        /// <param name="pt"></param>
418
        /// <param name="dx"></param>
419
        /// <param name="dy"></param>
420 233ef333 taeseongkim
        public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false)
421 d2114d3b humkyung
        {
422
            IPath path = (this as IPath);
423
424
            Point selected = MathSet.getNearPoint(path.PointSet, pt);
425
            selected.X += dx;
426
            selected.Y += dy;
427
428 9005f973 humkyung
            int idx = (this as IPath).PointSet.FindIndex(x => x.Equals(pt));
429
430
            var OppositeP = (idx + path.PointSet.Count / 2) % path.PointSet.Count;
431
            var PreviousP = (idx + (path.PointSet.Count - 1)) % path.PointSet.Count;
432
            var NextP = (idx + 1) % path.PointSet.Count;
433 ab7fe8c0 humkyung
            if (bAxisLocked)
434
            {
435 9005f973 humkyung
                var PrevV = path.PointSet[PreviousP] - path.PointSet[OppositeP];
436
                double PrevLength = PrevV.Length;
437
                PrevV.Normalize();
438 d2114d3b humkyung
439 ab7fe8c0 humkyung
                var NextV = path.PointSet[NextP] - path.PointSet[OppositeP];
440 9005f973 humkyung
                double NextVLength = NextV.Length;
441 ab7fe8c0 humkyung
                NextV.Normalize();
442 d2114d3b humkyung
443 9005f973 humkyung
                double _dx = selected.X - path.PointSet[OppositeP].X;
444
                double _dy = selected.Y - path.PointSet[OppositeP].Y;
445
                var dir = new Vector(_dx, _dy);
446
                if (PrevLength > NextVLength)
447
                {
448
                    double ratio = NextVLength / PrevLength;
449
450
                    double dot = MathSet.DotProduct(PrevV.X, PrevV.Y, dir.X, dir.Y);
451
452
                    path.PointSet[PreviousP] = path.PointSet[OppositeP] + PrevV * dot;
453
                    path.PointSet[NextP] = path.PointSet[OppositeP] + NextV * dot * ratio;
454
                    path.PointSet[idx] = path.PointSet[OppositeP] + PrevV * dot + NextV * dot * ratio;
455
                }
456
                else
457
                {
458
                    double ratio = PrevLength / NextVLength;
459
460
                    double dot = MathSet.DotProduct(NextV.X, NextV.Y, dir.X, dir.Y);
461
462
                    path.PointSet[PreviousP] = path.PointSet[OppositeP] + PrevV * dot * ratio;
463
                    path.PointSet[NextP] = path.PointSet[OppositeP] + NextV * dot;
464
                    path.PointSet[idx] = path.PointSet[OppositeP] + PrevV * dot * ratio + NextV * dot;
465
                }
466 ab7fe8c0 humkyung
            }
467
            else
468
            {
469
                var PreviousV = MathSet.GetNormVectorBetween(path.PointSet[OppositeP], path.PointSet[PreviousP]);
470 9005f973 humkyung
                var l = MathSet.DotProduct(PreviousV.X, PreviousV.Y, path.PointSet[idx].X - path.PointSet[OppositeP].X,
471
                    path.PointSet[idx].Y - path.PointSet[OppositeP].Y);
472 ab7fe8c0 humkyung
                path.PointSet[PreviousP] = new Point(path.PointSet[OppositeP].X + PreviousV.X * l, path.PointSet[OppositeP].Y + PreviousV.Y * l);
473
474
                var NextV = MathSet.GetNormVectorBetween(path.PointSet[OppositeP], path.PointSet[NextP]);
475 9005f973 humkyung
                l = MathSet.DotProduct(NextV.X, NextV.Y, path.PointSet[idx].X - path.PointSet[OppositeP].X, path.PointSet
476
                    [idx].Y - path.PointSet[OppositeP].Y);
477 ab7fe8c0 humkyung
                path.PointSet[NextP] = new Point(path.PointSet[OppositeP].X + NextV.X * l, path.PointSet[OppositeP].Y + NextV.Y * l);
478 9005f973 humkyung
479
                path.PointSet[idx] = selected;
480 ab7fe8c0 humkyung
            }
481 d2114d3b humkyung
482 0d00f9c8 humkyung
            this.UpdateControl();
483 d2114d3b humkyung
        }
484
485
        /// <summary>
486 91efe37a humkyung
        /// return ImgControl's area
487
        /// </summary>
488
        /// <author>humkyung</author>
489
        /// <date>2019.06.13</date>
490
        public override Rect ItemRect
491
        {
492
            get
493
            {
494
                double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X);
495
                double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y);
496
                double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X);
497
                double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y);
498
499
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
500
            }
501
        }
502
503
        /// <summary>
504 036650a0 humkyung
        /// Serialize this
505
        /// </summary>
506
        /// <param name="sUserId"></param>
507
        /// <returns></returns>
508
        public override string Serialize()
509
        {
510 b2d0f316 humkyung
            using (S_ImgControl ctrl = new S_ImgControl())
511 036650a0 humkyung
            {
512 b2d0f316 humkyung
                ctrl.Angle = this.CommentAngle;
513
                ctrl.EndPoint = this.EndPoint;
514
                ctrl.LB = this.LeftBottomPoint;
515
                ctrl.Name = this.GetType().Name;
516
                ctrl.PointSet = this.PointSet;
517
                ctrl.StartPoint = this.StartPoint;
518
                ctrl.UserID = this.UserID;
519
                ctrl.Opac = this.Opacity;
520
                ctrl.TR = this.TopRightPoint;
521
                ctrl.ImagePath = this.FilePath;
522 036650a0 humkyung
                ///강인구 추가(2017.11.02)
523
                ///Memo 추가
524 b2d0f316 humkyung
                ctrl.Memo = this.Memo;
525 036650a0 humkyung
526 b2d0f316 humkyung
                ctrl.ZIndex = this.ZIndex;
527
528
                return "|DZ|" + JsonSerializerHelper.CompressString((ctrl.JsonSerialize()));
529 036650a0 humkyung
            }
530
        }
531 661b7416 humkyung
532
        /// <summary>
533
        /// create a imgcontrol from given string
534
        /// </summary>
535
        /// <param name="str"></param>
536
        /// <returns></returns>
537 a1e2ba68 taeseongkim
        public static ImgControl FromString(string str, SolidColorBrush brush, string sProjectNo, string baseUri)
538 661b7416 humkyung
        {
539
            ImgControl instance = null;
540 ef7ba61f humkyung
            try
541 661b7416 humkyung
            {
542 ef7ba61f humkyung
                using (S_ImgControl s = JsonSerializerHelper.JsonDeserialize<S_ImgControl>(str))
543 661b7416 humkyung
                {
544 ef7ba61f humkyung
                    UriBuilder downloadUri = new UriBuilder(baseUri);
545
                    UriBuilder uri = new UriBuilder(s.ImagePath);
546
                    uri.Host = downloadUri.Host;
547
                    uri.Port = downloadUri.Port;
548
549
                    Image img = new Image();
550
                    if (s.ImagePath.Contains(".svg"))
551
                    {
552
                        SharpVectors.Converters.SvgImageExtension svgImage = new SharpVectors.Converters.SvgImageExtension(uri.ToString());
553
                        var svg = svgImage.ProvideValue(null);
554
555
                        img.Source = (DrawingImage)svg;
556
                    }
557
                    else
558
                    {
559
                        img.Source = new BitmapImage(uri.Uri);
560
                    }
561
562
                    instance = new ImgControl
563
                    {
564
                        CommentAngle = s.Angle,
565
                        StartPoint = s.StartPoint,
566
                        TopRightPoint = s.TR,
567
                        EndPoint = s.EndPoint,
568
                        LeftBottomPoint = s.LB,
569
                        PointSet = s.PointSet,
570
                        Opacity = s.Opac,
571
                        FilePath = uri.Uri.ToString(),
572
                        UserID = s.UserID,
573
                        ImageData = img.Source,
574
                        Memo = s.Memo,
575
                        ZIndex = s.ZIndex
576
                    };
577
578
                    instance.ImageData = img.Source;
579 661b7416 humkyung
                }
580 ef7ba61f humkyung
            }
581
            catch (Exception)
582
            {
583 661b7416 humkyung
            }
584
585
            return instance;
586
        }
587 787a4489 KangIngu
    }
588
}
클립보드 이미지 추가 (최대 크기: 500 MB)