markus / KCOM / Common / Converter / SvgImageConverter.cs @ 606884bf
이력 | 보기 | 이력해설 | 다운로드 (1.6 KB)
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 : IValueConverter |
16 |
{ |
17 |
|
18 |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
19 |
{ |
20 |
if(value == null) |
21 |
{ |
22 |
return null; |
23 |
} |
24 |
|
25 |
//var uri = string.Format("pack://application:,,,/images/{0}{1}.png", values); // for example |
26 |
var uri = value.ToString(); |
27 |
|
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 |
|
51 |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
52 |
{ |
53 |
throw new NotImplementedException(); |
54 |
} |
55 |
} |
56 |
} |