프로젝트

일반

사용자정보

개정판 a74e3cbc

IDa74e3cbc3562db9c6407263b4482cf15871550c4
상위 f1f56bcc
하위 684ef11c

이지연이(가) 5년 이상 전에 추가함

issue #886: legend를 이용한 심볼 생성 작업 중

Change-Id: I8dbd11c21078086a0335445d10c904e516251627

차이점 보기:

KCOM/Common/Converter/SvgConverter.cs
1
using KCOMDataModel.DataModel;
2
using System;
3
using System.Diagnostics;
4
using System.Text;
5
using System.Windows;
6
using System.Windows.Media.Imaging;
7

  
8
namespace KCOM.Common.Converter
9
{
10
    class SvgConverter
11
    {
12
        public DOCUMENT_ITEM _DocItem;
13

  
14
        public void SvgConvert(string fileurl, string guid, string DOCUMENT_NO)
15
        {
16
            var defaultBitmapImage = new BitmapImage();
17
            defaultBitmapImage.BeginInit();
18
            defaultBitmapImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
19
            defaultBitmapImage.CacheOption = BitmapCacheOption.OnLoad;
20
            defaultBitmapImage.UriSource = new Uri(fileurl);
21
            defaultBitmapImage.EndInit();
22

  
23
            GC.Collect();
24
            System.Drawing.Bitmap image;
25

  
26
            if (defaultBitmapImage.IsDownloading)
27
            {
28
                defaultBitmapImage.DownloadCompleted += (ex, arg) =>
29
                {
30
                    defaultBitmapImage.Freeze();
31
                    GC.Collect();
32

  
33
                    image = GetBitmap(defaultBitmapImage);
34

  
35
                    image.Save(@AppDomain.CurrentDomain.BaseDirectory + "potrace.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
36

  
37
                    Process potrace = new Process
38
                    {
39
                        StartInfo = new ProcessStartInfo
40
                        {
41
                            //FileName = @"http://cloud.devdoftech.co.kr:5977/UserData/"+ "potrace.exe",
42
                            FileName = @AppDomain.CurrentDomain.BaseDirectory + "potrace.exe",
43
                            //Arguments = "-s -u 1", //SVG
44
                            //Arguments = "- -o- --svg",
45
                            //Arguments = filename2 + "  --backend svg",
46
                            //Arguments = @AppDomain.CurrentDomain.BaseDirectory + "potrace.bmp" + "  --backend svg -i",
47
                            //Arguments = "-b svg -i " + @AppDomain.CurrentDomain.BaseDirectory + "potrace.bmp",
48
                            Arguments = "-b svg " + @AppDomain.CurrentDomain.BaseDirectory + "potrace.bmp",
49
                            RedirectStandardInput = true,
50
                            RedirectStandardOutput = true,
51
                            //RedirectStandardError = Program.IsDebug,
52
                            RedirectStandardError = true,
53
                            UseShellExecute = false,
54
                            CreateNoWindow = true,
55
                            WindowStyle = ProcessWindowStyle.Hidden
56
                        },
57
                        EnableRaisingEvents = false
58
                    };
59

  
60
                    StringBuilder svgBuilder = new StringBuilder();
61
                    potrace.OutputDataReceived += (object sender2, DataReceivedEventArgs e2) => {
62
                        svgBuilder.AppendLine(e2.Data);
63
                    };
64

  
65
                    potrace.Start();
66

  
67

  
68
                    byte[] bytes = System.IO.File.ReadAllBytes(@AppDomain.CurrentDomain.BaseDirectory + "potrace.bmp");
69
                    kr.co.devdoftech.cloud.FileUpload fileUploader = new kr.co.devdoftech.cloud.FileUpload();
70
                    fileurl = fileUploader.Run(App.ViewInfo.ProjectNO, DOCUMENT_NO, App.ViewInfo.UserID, guid + ".svg", bytes);
71
                };
72
            }
73
        }
74

  
75
        System.Drawing.Bitmap GetBitmap(BitmapSource source)
76
        {
77
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(source.PixelWidth, source.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
78
            System.Drawing.Imaging.BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
79
            source.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
80
            bmp.UnlockBits(data);
81
            return bmp;
82
        }
83
    }
84
}
KCOM/Common/Converter/SvgImageConverter.cs
1
using Svg2Xaml;
2
using System;
3
using System.Collections.Generic;
4
using System.Globalization;
5
using System.Linq;
6
using System.Text;
7
using System.Threading.Tasks;
8
using System.Windows.Controls;
9
using System.Windows.Data;
10
using System.Windows.Media;
11
using System.Windows.Media.Imaging;
12

  
13
namespace KCOM.Common.Converter
14
{
15
    class SvgImageConverter : IMultiValueConverter
16
    {
17
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
18
        {
19
            //var uri = string.Format("pack://application:,,,/images/{0}{1}.png", values); // for example
20
            var uri = values[0].ToString();
21

  
22
            Image img = new Image();
23
            if (uri.Contains(".svg"))
24
            {
25
                byte[] imageData = null;
26
                DrawingImage image = null;
27
                using (System.Net.WebClient web = new System.Net.WebClient())
28
                {
29
                    imageData = web.DownloadData(new Uri(uri));
30
                    System.IO.Stream stream = new System.IO.MemoryStream(imageData);
31
                    image = SvgReader.Load(stream);
32
                }
33
                img.Source = image;
34

  
35
            }
36
            else
37
            {
38
                img.Source = new BitmapImage(new Uri(uri));
39
            }
40

  
41
            //return new BitmapImage(new Uri(uri));
42
            return img.Source;
43
        }
44
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
45
        {
46
            throw new NotImplementedException();
47
        }
48
    }
49
}

내보내기 Unified diff

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