订单图片不显示问题修复 读单拍单卡死问题修复

This commit is contained in:
wule committed 2026-08-04 22:52:02 +08:00
1 parent fb4bafd4d8
commit 4a7af051b2
13 files changed
+295 -120

No files matched your search

@@ -24,7 +24,7 @@ namespace _29WxOrderWpf.Converters
//var bitMap = new BitmapImage(new Uri(url));
BitmapImage bitMap = null;
//bitMap = LoadImageFromUrl(url + "?imageView2/1/w/100/format/webp|imageMogr2/auto-orient=");
bitMap = LoadImageFromUrl(url);
bitMap = AllBase.ImageBuild.LoadBitmipImageFromUrl(url);
return bitMap;
//string errStr = "";
//var bitmapImg = GetUrlImg(url, out errStr);
@@ -43,38 +43,5 @@ namespace _29WxOrderWpf.Converters
{
throw new NotImplementedException(); // 不需要反向转换,所以不实现。
}
public static 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;
}
}
}