ScreenToGif/Util/Converters/UriToBitmap.cs

(完整代码) 1KB

using System;
using System.IO;
using System.Windows.Data;
using ScreenToGif.ImageUtil;

namespace ScreenToGif.Util.Converters
{
    /// <summary>
    /// URI to BitmapImage converter.
    /// </summary>
    public class UriToBitmap : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var stringValue = value as string;
            var size = parameter as string;

            if (string.IsNullOrEmpty(stringValue))
                return null; //DependencyProperty.UnsetValue;

            if (!File.Exists(stringValue))
                return null;

            //BitmapImage bi = new BitmapImage();
            //bi.BeginInit();

            //if (!String.IsNullOrEmpty(size))
            //    bi.DecodePixelHeight = System.Convert.ToInt32(size);

            //bi.CacheOption = BitmapCacheOption.OnLoad;
            //bi.UriSource = new Uri(stringValue);
            //bi.EndInit();

            //return bi;

            
            if (!string.IsNullOrEmpty(size))
                return stringValue.SourceFrom(System.Convert.ToInt32(size));

            return stringValue.SourceFrom();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。