markus / KCOM / Common / Converter / SvgImageConverter.cs @ 504c5aa1
이력 | 보기 | 이력해설 | 다운로드 (1.6 KB)
1 | a74e3cbc | ljiyeon | 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 | f65e6c02 | taeseongkim | class SvgImageConverter : IValueConverter |
16 | a74e3cbc | ljiyeon | { |
17 | f65e6c02 | taeseongkim | |
18 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
||
19 | a74e3cbc | ljiyeon | { |
20 | f65e6c02 | taeseongkim | if(value == null) |
21 | { |
||
22 | return null; |
||
23 | } |
||
24 | |||
25 | a74e3cbc | ljiyeon | //var uri = string.Format("pack://application:,,,/images/{0}{1}.png", values); // for example |
26 | f65e6c02 | taeseongkim | var uri = value.ToString(); |
27 | a74e3cbc | ljiyeon | |
28 | Image img = new Image(); |
||
29 | if (uri.Contains(".svg")) |
||
30 | { |
||
31 | byte[] imageData = null; |
||
32 | DrawingImage image = null; |
||
33 | using (System.Net.WebClient web = new System.Net.WebClient()) |
||
34 | { |
||
35 | imageData = web.DownloadData(new Uri(uri)); |
||
36 | System.IO.Stream stream = new System.IO.MemoryStream(imageData); |
||
37 | image = SvgReader.Load(stream); |
||
38 | } |
||
39 | img.Source = image; |
||
40 | |||
41 | } |
||
42 | else |
||
43 | { |
||
44 | img.Source = new BitmapImage(new Uri(uri)); |
||
45 | } |
||
46 | |||
47 | //return new BitmapImage(new Uri(uri)); |
||
48 | return img.Source; |
||
49 | } |
||
50 | f65e6c02 | taeseongkim | |
51 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
||
52 | a74e3cbc | ljiyeon | { |
53 | throw new NotImplementedException(); |
||
54 | } |
||
55 | } |
||
56 | } |