12345678910111213141516171819202122232425262728293031323334353637383940 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Data;
- using System.Windows.Media.Imaging;
- namespace LogoForceTestApp.Modules.MainModule.ViewModels
- {
- public sealed class PathToImageConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (value == null)
- {
- return null;
- }
- string uriStr = (string)value;
- Uri uri = new Uri(uriStr, UriKind.Absolute);
- BitmapImage bmp = new BitmapImage();
- bmp.DecodePixelHeight = 200; // 确定解码高度,宽度不同时设置
- bmp.BeginInit();
- // 延迟,必要时创建
- bmp.CreateOptions = BitmapCreateOptions.DelayCreation;
- bmp.CacheOption = BitmapCacheOption.OnLoad;
- bmp.UriSource = uri;
- bmp.EndInit(); //结束初始化
- return bmp;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return null;
- }
- }
- }
|