48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Data;
|
|
using System.Windows.Media.Imaging;
|
|
using Work;
|
|
|
|
namespace _29WxOrderWpf.Converters
|
|
{
|
|
public class ImageUrlToBitmapImageConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is string url && Uri.IsWellFormedUriString(url, UriKind.Absolute))
|
|
{
|
|
try
|
|
{
|
|
// 直接加载绑定如果遇到有问题的网络图片会直接崩溃。
|
|
//var bitMap = new BitmapImage(new Uri(url));
|
|
BitmapImage bitMap = null;
|
|
//bitMap = LoadImageFromUrl(url + "?imageView2/1/w/100/format/webp|imageMogr2/auto-orient=");
|
|
bitMap = AllBase.ImageBuild.LoadBitmipImageFromUrl(url);
|
|
return bitMap;
|
|
//string errStr = "";
|
|
//var bitmapImg = GetUrlImg(url, out errStr);
|
|
//return bitmapImg;
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
//return Task.Run(() => new BitmapImage(new Uri(url))); // 使用 Task.Run 来异步加载图片。
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException(); // 不需要反向转换,所以不实现。
|
|
}
|
|
}
|
|
}
|