markus / KCOM / Common / Converter / SvgConverter.cs @ 3abe8d4e
이력 | 보기 | 이력해설 | 다운로드 (3.64 KB)
1 | a74e3cbc | ljiyeon | 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 void SvgConvert(string fileurl, string guid, string DOCUMENT_NO) |
||
13 | { |
||
14 | c73426a9 | ljiyeon | try |
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 | a74e3cbc | ljiyeon | |
23 | c73426a9 | ljiyeon | GC.Collect(); |
24 | System.Drawing.Bitmap image; |
||
25 | a74e3cbc | ljiyeon | |
26 | c73426a9 | ljiyeon | if (defaultBitmapImage.IsDownloading) |
27 | a74e3cbc | ljiyeon | { |
28 | c73426a9 | ljiyeon | defaultBitmapImage.DownloadCompleted += (ex, arg) => |
29 | { |
||
30 | defaultBitmapImage.Freeze(); |
||
31 | GC.Collect(); |
||
32 | a74e3cbc | ljiyeon | |
33 | c73426a9 | ljiyeon | image = GetBitmap(defaultBitmapImage); |
34 | a74e3cbc | ljiyeon | |
35 | c73426a9 | ljiyeon | image.Save(@AppDomain.CurrentDomain.BaseDirectory + "potrace.bmp", System.Drawing.Imaging.ImageFormat.Bmp); |
36 | a74e3cbc | ljiyeon | |
37 | c73426a9 | ljiyeon | Process potrace = new Process |
38 | a74e3cbc | ljiyeon | { |
39 | c73426a9 | ljiyeon | StartInfo = new ProcessStartInfo |
40 | { |
||
41 | FileName = @AppDomain.CurrentDomain.BaseDirectory + "potrace.exe", |
||
42 | Arguments = "-b svg " + @AppDomain.CurrentDomain.BaseDirectory + "potrace.bmp", |
||
43 | RedirectStandardInput = true, |
||
44 | RedirectStandardOutput = true, |
||
45 | RedirectStandardError = true, |
||
46 | UseShellExecute = false, |
||
47 | CreateNoWindow = true, |
||
48 | WindowStyle = ProcessWindowStyle.Hidden |
||
49 | }, |
||
50 | EnableRaisingEvents = false |
||
51 | }; |
||
52 | a74e3cbc | ljiyeon | |
53 | c73426a9 | ljiyeon | StringBuilder svgBuilder = new StringBuilder(); |
54 | potrace.OutputDataReceived += (object sender2, DataReceivedEventArgs e2) => |
||
55 | { |
||
56 | svgBuilder.AppendLine(e2.Data); |
||
57 | }; |
||
58 | |||
59 | potrace.Start(); |
||
60 | a74e3cbc | ljiyeon | |
61 | |||
62 | c73426a9 | ljiyeon | byte[] bytes = System.IO.File.ReadAllBytes(@AppDomain.CurrentDomain.BaseDirectory + "potrace.bmp"); |
63 | 76dc223b | taeseongkim | kr.co.devdoftech.cloud.FileUpload fileUploader = App.FileUploader; |
64 | c73426a9 | ljiyeon | fileurl = fileUploader.Run(App.ViewInfo.ProjectNO, DOCUMENT_NO, App.ViewInfo.UserID, guid + ".svg", bytes); |
65 | a74e3cbc | ljiyeon | |
66 | c73426a9 | ljiyeon | Check_Uri.UriCheck(fileurl); |
67 | }; |
||
68 | } |
||
69 | } |
||
70 | catch (Exception ex) |
||
71 | { |
||
72 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert"); |
||
73 | a74e3cbc | ljiyeon | } |
74 | } |
||
75 | |||
76 | System.Drawing.Bitmap GetBitmap(BitmapSource source) |
||
77 | { |
||
78 | System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(source.PixelWidth, source.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); |
||
79 | 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); |
||
80 | source.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride); |
||
81 | bmp.UnlockBits(data); |
||
82 | return bmp; |
||
83 | } |
||
84 | } |
||
85 | } |