12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- /* ==============================================================================
- * 功能描述:StringToImageConverter
- * 创 建 者:Garrett
- * 创建日期:2018/3/9 17:09:51
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Data;
- using System.Windows.Media.Imaging;
- using System.Windows.Resources;
- using System.Windows;
- namespace SAGA.DotNetUtils.WPF.Converter
- {
- /// <summary>
- /// StringToImageConverter
- /// </summary>
- public class StringToImageConverter:IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- BitmapImage img = new BitmapImage();
- if (value == null) return img;
- //若要原始文件的站点,可以调用 Application 类的 GetRemoteStream 方法,同时传递标识原始文件的所需站点的 pack URI。 GetRemoteStream 将返回一个 StreamResourceInfo 对象,该对象将原始文件的该站点作为 Stream 公开,并描述其内容类型。
- var uri = new Uri(value.ToString().Replace("%20", " "), UriKind.Relative);
- StreamResourceInfo info = Application.GetRemoteStream(uri);
- img.BeginInit();
- //img.UriSource = new Uri(value.ToString(), UriKind.Relative);
- img.StreamSource = info.Stream;
- img.EndInit();
- return img;
- }
- public object ConvertBack(object value, Type targetType, object parameter,
- System.Globalization.CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- }
|