123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- /* ==============================================================================
- * 功能描述:StringToImageConverter
- * 创 建 者:Garrett
- * 创建日期:2018/3/9 17:09:51
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.IO;
- 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;
- using System.Windows.Media;
- 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;
- try
- {
- var bytes = File.ReadAllBytes(value.ToString());
- img.BeginInit();
- img.StreamSource = new MemoryStream(bytes);
- img.EndInit();
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- img = null;
- }
- return img;
- }
- public object ConvertBack(object value, Type targetType, object parameter,
- System.Globalization.CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- }
|