修改买手单号状态
This commit is contained in:
1 parent
1e27c0b1e1
commit
adde7e6fca
22 files changed
+6451
-514
No files matched your search
@@ -1,11 +1,14 @@
|
||||
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
|
||||
{
|
||||
@@ -15,7 +18,20 @@ namespace _29WxOrderWpf.Converters
|
||||
{
|
||||
if (value is string url && Uri.IsWellFormedUriString(url, UriKind.Absolute))
|
||||
{
|
||||
return new BitmapImage(new Uri(url));
|
||||
try
|
||||
{
|
||||
// 直接加载绑定如果遇到有问题的网络图片会直接崩溃。
|
||||
//var bitMap = new BitmapImage(new Uri(url));
|
||||
var bitMap = LoadImageFromUrl(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;
|
||||
@@ -25,5 +41,38 @@ namespace _29WxOrderWpf.Converters
|
||||
{
|
||||
throw new NotImplementedException(); // 不需要反向转换,所以不实现。
|
||||
}
|
||||
|
||||
|
||||
public BitmapImage LoadImageFromUrl(string url)
|
||||
{
|
||||
BitmapImage bitmap = new BitmapImage();
|
||||
|
||||
try
|
||||
{
|
||||
using (WebClient webClient = new WebClient())
|
||||
{
|
||||
// 下载图片数据到内存流
|
||||
using (MemoryStream stream = new MemoryStream(webClient.DownloadData(url)))
|
||||
{
|
||||
stream.Position = 0; // 重置流的位置到开始处
|
||||
bitmap.BeginInit();
|
||||
bitmap.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
|
||||
bitmap.CacheOption = BitmapCacheOption.OnLoad; // 或者使用 BitmapCacheOption.OnLoad 以减少内存使用
|
||||
bitmap.UriSource = null; // 清除可能的旧UriSource,防止缓存问题
|
||||
bitmap.StreamSource = stream;
|
||||
bitmap.EndInit();
|
||||
bitmap.Freeze(); // 防止后续更改,提高性能
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 处理异常,例如打印错误信息或设置一个默认图片等
|
||||
//Console.WriteLine("Error loading image: " + ex.Message);
|
||||
return null;
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user