프로젝트

일반

사용자정보

개정판 0d97ab05

ID0d97ab05b0b770e7e9cffa5c8bd7cda07e5244cb
상위 dea3d68a
하위 53f99751, a197bf6f

백흠경이(가) 5달 전에 추가함

Fix: SVG,PNG 심볼 저장 오류 수정

Change-Id: Ief726d6e933a9fbc3ceb8e67805de83eb8986d84

차이점 보기:

KCOM/App.xaml.cs
347 347
                }
348 348

  
349 349
                App.FileLogger.Debug(_EndPoint.Uri);
350

  
351 350
#if !DEBUG
352 351
#endif
353 352
                //var license = new License.Validator.Valid(BaseAddress + "/License");
354

  
355 353
                //license.ValidateError += License_ValidateError;
356

  
357 354
                //license.GetLicense("public.xml");
358

  
359 355
                //if (license.Activate())
360 356
                //{
361

  
362 357
                //}
363 358
                //else
364 359
                //{
365

  
366 360
                //}
367 361

  
368

  
369 362
                await SplashScreenAsnyc();
370 363

  
371 364
                base.OnStartup(e);
KCOM/Controls/Symbol.xaml.cs
106 106

  
107 107
        private async Task DataBindAsync()
108 108
        {
109
            //lstSymbolPrivate.ItemsSource = null;
110
            //lstSymbolPublic.ItemsSource = null;
111

  
112
            Symbol_Custom Custom = new Symbol_Custom();
113
            List<Symbol_Custom> Custom_List = new List<Symbol_Custom>();
114

  
115 109
            try
116 110
            {
111
                List<Symbol_Custom> PrivateSymbolList = new List<Symbol_Custom>();
117 112

  
118 113
                var symbol_Private = await ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseTaskClient.GetSymbolListAsync(App.ViewInfo.UserID);
119

  
120 114
                foreach (var item in symbol_Private)
121 115
                {
116
                    var Custom = new Symbol_Custom();
122 117
                    Custom.Name = item.NAME;
123 118
                    Custom.ImageUri = CommonLib.Common.IPReplace(item.IMAGE_URL.Replace("//","/").Replace(":/", "://"), App.isExternal);
124 119
                    Custom.ID = item.ID;
125
                    Custom_List.Add(Custom);
126
                    Custom = new Symbol_Custom();
120
                    PrivateSymbolList.Add(Custom);
127 121
                }
128
                lstSymbolPrivate.ItemsSource = Custom_List;
122
                lstSymbolPrivate.ItemsSource = PrivateSymbolList;
129 123
            }
130 124
            catch (Exception ex)
131 125
            {
132 126
                System.Diagnostics.Debug.WriteLine(ex.ToString());
133 127
            }
134 128

  
135
            Custom = new Symbol_Custom();
136
            Custom_List = new List<Symbol_Custom>();
137

  
138 129
            deptlist.ItemsSource = await ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseTaskClient.GetPublicSymbolDeptListAsync();
139 130

  
140 131
            List<SYMBOL_PUBLIC> symbol_Public;
141

  
142

  
143 132
            if (deptlist.SelectedValue != null)
144 133
            {
145 134
                symbol_Public = await ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseTaskClient.GetPublicSymbolListAsync(deptlist.SelectedValue.ToString());
......
151 140

  
152 141
            if (symbol_Public != null)
153 142
            {
143
                var PublicSymbolList = new List<Symbol_Custom>();
154 144
                foreach (var item in symbol_Public)
155 145
                {
146
                    var Custom = new Symbol_Custom();
156 147
                    Custom.Name = item.NAME;
157 148
                    Custom.ImageUri = CommonLib.Common.IPReplace(item.IMAGE_URL.Replace("//", "/").Replace(":/", "://"), App.isExternal);
158 149
                    Custom.ID = item.ID;
159
                    Custom_List.Add(Custom);
160
                    Custom = new Symbol_Custom();
150
                    PublicSymbolList.Add(Custom);
161 151
                }
162 152

  
163
                lstSymbolPublic.ItemsSource = Custom_List;
153
                lstSymbolPublic.ItemsSource = PublicSymbolList;
164 154
            }
165 155
        }
166 156

  
167 157
        public async Task<PngBitmapEncoder> symImageAsync_old(string data,double PageAngle)
168 158
        {
169

  
170 159
            Canvas _canvas = new Canvas();
171 160
            _canvas.Background = Brushes.White;
172 161
            _canvas.Width = finalItem.BorderSize.Width;
KCOM/Views/MainMenu.xaml.cs
33 33
using Telerik.Windows.Controls;
34 34
using Telerik.Windows.Controls.GridView;
35 35
using Telerik.Windows.Data;
36
//using static KCOM.TempFile;
36
using ZoomAndPan;
37 37

  
38 38
namespace KCOM.Views
39 39
{
......
135 135
        public Point CanvasDrawingMouseDownPoint;
136 136

  
137 137
        public string filename { get; set; }
138
        private Point canvasZoomPanningMouseDownPoint;
138
        private Point canvasZoomPanningMouseDownPoint { get; set; }
139
        private Point zoomAndPanControlMouseDownPoint { get; set; }
140

  
139 141
        public Point getCurrentPoint;
140 142
        private Point canvasZoommovingMouseDownPoint;
141 143
        private List<object> ControlList = new List<object>();
......
2298 2300
                            {
2299 2301
                                dragCaptureBorder.Visibility = Visibility.Collapsed;
2300 2302
                                mouseHandlingMode = MouseHandlingMode.None;
2301
                                Point endPoint = e.GetPosition(zoomAndPanCanvas);
2302 2303
                                symbolselectindex = symbolPanel_Instance.RadTab.SelectedIndex;
2303
                                Set_Symbol_Capture(endPoint);
2304
                                Point endPoint = e.GetPosition(zoomAndPanControl);
2305
                                CaptureSymbolImage(endPoint);
2304 2306
                                ViewerDataModel.Instance.ViewVisible = Visibility.Collapsed;
2305 2307
                                ViewerDataModel.Instance.ViewVisible = Visibility.Visible;
2306 2308
                                ViewerDataModel.Instance.Capture_Opacity = 0;
......
2370 2372
            //controlType = ControlType.SingleLine;
2371 2373
        }
2372 2374

  
2373
        public void Set_Symbol_Capture(Point endPoint)
2375
        /// <summary>
2376
        /// 주어진 좌표의 영역으로 심볼을 생성한다.
2377
        /// </summary>
2378
        /// <param name="endPoint"></param>
2379
        public void CaptureSymbolImage(Point endPoint)
2374 2380
        {
2375
            double x = CanvasDrawingMouseDownPoint.X;
2376
            double y = CanvasDrawingMouseDownPoint.Y;
2377
            if (x > endPoint.X)
2378
            {
2379
                x = endPoint.X;
2380
                y = endPoint.Y;
2381
            }
2382

  
2383
            double width = dragCaptureBorder.Width;
2384
            double height = dragCaptureBorder.Height;
2381
            double x = Math.Min(zoomAndPanControlMouseDownPoint.X, endPoint.X);
2382
            double y = Math.Min(zoomAndPanControlMouseDownPoint.Y, endPoint.Y);
2383
            double width = Math.Abs(zoomAndPanControlMouseDownPoint.X - endPoint.X);
2384
            double height = Math.Abs(zoomAndPanControlMouseDownPoint.Y - endPoint.Y);
2385 2385

  
2386
            canvasImage = ConverterBitmapImage(zoomAndPanCanvas);
2387

  
2388
            if (x < 0)
2386
            if (width > 0 && height > 0)
2389 2387
            {
2390
                width += x;
2391
                x = 0;
2392
            }
2393
            if (y < 0)
2394
            {
2395
                height += y;
2396
                y = 0;
2388
                var SymbolRect = new Int32Rect((int)x, (int)y, (int)width, (int)height);
2397 2389

  
2398
                width = (int)canvasImage.PixelWidth - x;
2399
            }
2400
            if (x + width > canvasImage.PixelWidth)
2401
            {
2402
                width = (int)canvasImage.PixelWidth - x;
2403
            }
2404
            if (y + height > canvasImage.PixelHeight)
2405
            {
2406
                height = (int)canvasImage.PixelHeight - y;
2407
            }
2408
            var rect = new Int32Rect((int)x, (int)y, (int)width, (int)height);
2409

  
2410
            string uri = this.GetImageURL(_ViewInfo.DocumentItemID, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber);
2411
            var defaultBitmapImage = new BitmapImage();
2412
            defaultBitmapImage.BeginInit();
2413
            defaultBitmapImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
2414
            defaultBitmapImage.CacheOption = BitmapCacheOption.OnLoad;
2415
            defaultBitmapImage.UriSource = new Uri(uri);
2416
            defaultBitmapImage.EndInit();
2417

  
2418
            //GC.Collect();
2419

  
2420
            if (defaultBitmapImage.IsDownloading)
2421
            {
2422
                defaultBitmapImage.DownloadCompleted += (ex, arg) =>
2390
                canvasImage = ConverterBitmapImage(zoomAndPanControl);
2391
                BitmapSource crop = new CroppedBitmap(canvasImage, SymbolRect);
2392
#if DEBUG
2393
                BitmapEncoder pngEncoder = new PngBitmapEncoder();
2394
                pngEncoder.Frames.Add(BitmapFrame.Create(crop));
2395
                using (var fs = System.IO.File.OpenWrite(System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetTempFileName())))
2423 2396
                {
2424
                    defaultBitmapImage.Freeze();
2425
                    //GC.Collect();
2426
                    BitmapSource bs = new CroppedBitmap(defaultBitmapImage, rect);
2427
                    Save_Symbol_Capture(bs, (int)x, (int)y, (int)width, (int)height);
2428
                };
2397
                    pngEncoder.Save(fs);
2398
                }
2399
#endif
2400

  
2401
                double scale = dragCaptureBorder.Width / width;
2402
                SaveCapturedSymbol(crop, (int)x, (int)y, (int)width, (int)height, scale, scale);
2429 2403
            }
2430 2404
        }
2431 2405

  
......
2829 2803
            {
2830 2804
                CanvasDrawingMouseDownPoint = e.GetPosition(drawingRotateCanvas);
2831 2805
                canvasZoomPanningMouseDownPoint = e.GetPosition(zoomAndPanCanvas);
2806
                zoomAndPanControlMouseDownPoint = e.GetPosition(zoomAndPanControl);
2832 2807
                this.cursor = new Cursor(App.DefaultArrowCursorStream);
2833 2808
                SetCursor();
2834 2809

  
......
5511 5486
            }
5512 5487
        }
5513 5488

  
5514
        public int symbolselectindex = 0;
5489
        private int symbolselectindex { get; set; } = 0;
5515 5490

  
5516 5491
        /// <summary>
5517 5492
        /// 심볼을 저장한다.
......
5551 5526
                    {
5552 5527
                        try
5553 5528
                        {
5554
                            var defaultBitmapImage = new BitmapImage();
5555
                            defaultBitmapImage.BeginInit();
5556
                            defaultBitmapImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
5557
                            defaultBitmapImage.CacheOption = BitmapCacheOption.OnLoad;
5558
                            Check_Uri.UriCheck(filename);
5559
                            defaultBitmapImage.UriSource = new Uri(filename);
5560
                            defaultBitmapImage.EndInit();
5561

  
5562
                            System.Drawing.Bitmap image;
5563

  
5564
                            if (defaultBitmapImage.IsDownloading)
5529
                            using (System.IO.MemoryStream ms = new System.IO.MemoryStream(Img_byte))
5565 5530
                            {
5566
                                defaultBitmapImage.DownloadCompleted += (ex2, arg2) =>
5531
                                string BmpFilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetTempFileName());
5532
                                var bitmap = new System.Drawing.Bitmap(ms);
5533
                                bitmap.Save(BmpFilePath, System.Drawing.Imaging.ImageFormat.Bmp);
5534

  
5535
                                try
5567 5536
                                {
5568
                                    defaultBitmapImage.Freeze();
5569
                                    image = GetBitmap(defaultBitmapImage);
5570
                                    image.Save(@AppDomain.CurrentDomain.BaseDirectory + "potrace.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
5537
                                    var TempPath = System.IO.Path.GetTempPath();
5571 5538
                                    Process potrace = new Process
5572 5539
                                    {
5573 5540
                                        StartInfo = new ProcessStartInfo
5574 5541
                                        {
5575 5542
                                            FileName = @AppDomain.CurrentDomain.BaseDirectory + "potrace.exe",
5576
                                            Arguments = "-b svg " + @AppDomain.CurrentDomain.BaseDirectory + "potrace.bmp",
5543
                                            Arguments = "-b svg " + BmpFilePath,
5577 5544
                                            RedirectStandardInput = true,
5578 5545
                                            RedirectStandardOutput = true,
5579 5546
                                            RedirectStandardError = true,
......
5593 5560
                                    potrace.Start();
5594 5561
                                    potrace.Exited += (sender, e) =>
5595 5562
                                    {
5596
                                        byte[] bytes = System.IO.File.ReadAllBytes(@AppDomain.CurrentDomain.BaseDirectory + "potrace.svg");
5563
                                        byte[] bytes = System.IO.File.ReadAllBytes(System.IO.Path.Combine(TempPath, System.IO.Path.GetFileNameWithoutExtension(BmpFilePath) + ".svg"));
5597 5564
                                        svgfilename = fileUploader.Run(App.ViewInfo.ProjectNO, _DocItem.DOCUMENT_NO, App.ViewInfo.UserID, guid + ".svg", bytes);
5598 5565
                                        Check_Uri.UriCheck(svgfilename);
5599 5566
                                        if (symbolselectindex == 0)
......
5606 5573
                                        }
5607 5574
                                    };
5608 5575
                                    potrace.WaitForExit();
5609
                                };
5610
                            }
5611
                            else
5612
                            {
5613
                                //GC.Collect();
5576
                                }
5577
                                catch (Exception e)
5578
                                {
5579
                                    DialogMessage_Alert(e.Message, "Error");
5580
                                }
5614 5581
                            }
5615 5582
                        }
5616 5583
                        catch (Exception ee)
......
5626 5593
            }
5627 5594
        }
5628 5595

  
5596
        private void DefaultBitmapImage_DownloadFailed(object sender, ExceptionEventArgs e)
5597
        {
5598
            DialogMessage_Alert("Fail to download image : " + e.ErrorException.Message, "Error");
5599
        }
5600

  
5629 5601
        /// <summary>
5630 5602
        /// 개인 심볼을 저장한다.
5631 5603
        /// </summary>
......
5645 5617
                    DATA = Data
5646 5618
                };
5647 5619

  
5648
                ///Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveSymbolCompleted += BaseClient_SaveSymbolCompleted;
5649 5620
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveSymbolAsync(symbol_private);
5650 5621
            }
5651 5622
            catch (Exception ex)
......
5654 5625
            }
5655 5626
        }
5656 5627

  
5628
        private void BaseClient_SaveSymbolCompleted(object sender, ServiceDeepView.SaveSymbolCompletedEventArgs e)
5629
        {
5630
            Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate 
5631
            { 
5632
                BindSymbolData(); 
5633
            }));
5634
        }
5635

  
5657 5636
        /// <summary>
5658 5637
        /// 공용 심볼을 저장한다.
5659 5638
        /// </summary>
......
5673 5652
                    IMAGE_URL = Url,
5674 5653
                    DATA = Data
5675 5654
                };
5676
                ///Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddPublicSymbolCompleted += BaseClient_AddPublicSymbolCompleted;
5677 5655
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddPublicSymbol(symbol_public);
5678 5656
            }
5679 5657
            catch (Exception ex)
......
5684 5662

  
5685 5663
        private void BaseClient_AddPublicSymbolCompleted(object sender, ServiceDeepView.AddPublicSymbolCompletedEventArgs e)
5686 5664
        {
5687
            BindSymbolData();
5688
        }
5689

  
5690
        private void BaseClient_SaveSymbolCompleted(object sender, ServiceDeepView.SaveSymbolCompletedEventArgs e)
5691
        {
5692
            BindSymbolData();
5665
            Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate
5666
            {
5667
                BindSymbolData();
5668
            }));
5693 5669
        }
5670
        
5694 5671

  
5695 5672
        /// <summary>
5696 5673
        /// Symbol 데이터를 화면에 표시한다.
......
5699 5676
        {
5700 5677
            try
5701 5678
            {
5702
                Symbol_Custom Custom = new Symbol_Custom();
5703
                List<Symbol_Custom> Custom_List = new List<Symbol_Custom>();
5704

  
5705
                var symbol_Private = BaseClient.GetSymbolList(App.ViewInfo.UserID);
5706
                foreach (var item in symbol_Private)
5679
                #region Private Symbol을 표시한다.
5680
                List<Symbol_Custom> PrivateSymbolList = new List<Symbol_Custom>();
5681
                var PrivateSymbols = BaseClient.GetSymbolList(App.ViewInfo.UserID);
5682
                foreach (var symbol in PrivateSymbols)
5707 5683
                {
5708
                    Custom.Name = item.NAME;
5709
                    Custom.ImageUri = item.IMAGE_URL;
5710
                    Custom.ID = item.ID;
5711
                    Custom_List.Add(Custom);
5712
                    Custom = new Symbol_Custom();
5684
                    var Custom = new Symbol_Custom();
5685
                    Custom.Name = symbol.NAME;
5686
                    Custom.ImageUri = symbol.IMAGE_URL;
5687
                    Custom.ID = symbol.ID;
5688
                    PrivateSymbolList.Add(Custom);
5713 5689
                }
5714
                symbolPanel_Instance.lstSymbolPrivate.ItemsSource = Custom_List;
5715

  
5716
                Custom = new Symbol_Custom();
5717
                Custom_List = new List<Symbol_Custom>();
5690
                symbolPanel_Instance.lstSymbolPrivate.ItemsSource = PrivateSymbolList;
5691
                #endregion
5718 5692

  
5719 5693
                symbolPanel_Instance.deptlist.ItemsSource = BaseClient.GetPublicSymbolDeptList();
5720 5694

  
5721
                List<SYMBOL_PUBLIC> symbol_Public;
5722

  
5695
                #region Public Symbol을 표시한다.
5696
                List<SYMBOL_PUBLIC> PublicSymbols;
5723 5697
                if (symbolPanel_Instance.deptlist.SelectedValue != null)
5724 5698
                {
5725
                    symbol_Public = BaseClient.GetPublicSymbolList(symbolPanel_Instance.deptlist.SelectedValue.ToString());
5699
                    PublicSymbols = BaseClient.GetPublicSymbolList(symbolPanel_Instance.deptlist.SelectedValue.ToString());
5726 5700
                }
5727 5701
                else
5728 5702
                {
5729
                    symbol_Public = BaseClient.GetPublicSymbolList(null);
5703
                    PublicSymbols = BaseClient.GetPublicSymbolList(null);
5730 5704
                }
5731
                foreach (var item in symbol_Public)
5705

  
5706
                var PublicSymbolList = new List<Symbol_Custom>();
5707
                foreach (var symbol in PublicSymbols)
5732 5708
                {
5733
                    Custom.Name = item.NAME;
5734
                    Custom.ImageUri = item.IMAGE_URL;
5735
                    Custom.ID = item.ID;
5736
                    Custom_List.Add(Custom);
5737
                    Custom = new Symbol_Custom();
5709
                    var Custom = new Symbol_Custom();
5710
                    Custom.Name = symbol.NAME;
5711
                    Custom.ImageUri = symbol.IMAGE_URL;
5712
                    Custom.ID = symbol.ID;
5713
                    PublicSymbolList.Add(Custom);
5738 5714
                }
5739
                symbolPanel_Instance.lstSymbolPublic.ItemsSource = Custom_List;
5715
                symbolPanel_Instance.lstSymbolPublic.ItemsSource = PublicSymbolList;
5716
                #endregion
5740 5717
            }
5741 5718
            catch (Exception ex)
5742 5719
            {
......
5882 5859
            return bmp;
5883 5860
        }
5884 5861

  
5885
        public void Save_Symbol_Capture(BitmapSource source, int x, int y, int width, int height)
5862
        /// <summary>
5863
        /// 캡쳐한 심볼을 저장한다.
5864
        /// </summary>
5865
        /// <param name="source"></param>
5866
        /// <param name="x"></param>
5867
        /// <param name="y"></param>
5868
        /// <param name="width"></param>
5869
        /// <param name="height"></param>
5870
        public void SaveCapturedSymbol(BitmapSource source, int x, int y, int width, int height, double XScale = 1, double YScale = 1)
5886 5871
        {
5887
            System.Drawing.Bitmap image = GetBitmap(source);
5888
            //흰색 제거
5889
            //image.MakeTransparent(System.Drawing.Color.White);
5872
            var resized = new TransformedBitmap(source, new ScaleTransform(XScale, YScale));
5873
            System.Drawing.Bitmap image = GetBitmap(resized);
5890 5874

  
5891
            var imageStream = new System.IO.MemoryStream();
5892 5875
            byte[] imageBytes = null;
5893
            using (imageStream)
5876
            using (var imageStream = new System.IO.MemoryStream())
5894 5877
            {
5878
#if DEBUG
5879
                string TempFilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetTempFileName());
5880
                image.Save(TempFilePath);
5881
#endif
5895 5882
                image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
5896
                // test.Save(@"E:\test.png", System.Drawing.Imaging.ImageFormat.Png);
5897 5883
                imageStream.Position = 0;
5898 5884
                imageBytes = imageStream.ToArray();
5899 5885
            }

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)