markus / KCOM / Common / Converter / SvgImageConverter.cs @ 6f67c93d
이력 | 보기 | 이력해설 | 다운로드 (1.53 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 : 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 |
} |