优化上传商品图片

This commit is contained in:
wule committed 2026-10-21 13:43:16 +08:00
1 parent 059ac932a0
commit a09596378b
4 files changed
+149 -116

No files matched your search

+14 -1
View File
@@ -5,6 +5,7 @@
*
*/
using NaiBa.Util.Extension;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -12,6 +13,7 @@ using System.Drawing;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.InteropServices;
@@ -54,11 +56,22 @@ namespace AllBase
public static Image GetUrlImg(string imgUrl, out string rst)
{
rst = "";
if (imgUrl.IsNullOrEmpty())
{
rst = "图片路径为空";
return null;
}
//return LoadImage(imgUrl);
if (imgUrl.Contains("wxapp") || imgUrl.Contains("mmecimage.cn"))
{
return ImageBuild.LoadBitmapLoadBitmipImageFromUrl(imgUrl, out rst);
imgUrl = imgUrl.Split('?').FirstOrDefault() + "?imageView2/2/w/800/h/800/format/jpg/q/80";
var im = ImageBuild.LoadBitmapLoadBitmipImageFromUrl(imgUrl, out rst);
return im;
//if (im != null && string.IsNullOrEmpty(rst))
// return im;
//else
// rst = string.Empty;
}
Image image = null;
+24 -9
View File
@@ -592,17 +592,32 @@ namespace AllBase
public static Image LoadBitmapLoadBitmipImageFromUrl(string url, out string error)
{
try
BitmapImage bi = null;
try
{
BitmapImage bi = LoadBitmipImageFromUrl(url, out error);
return BitmapImageToSystemDrawingImage(bi);
bi = LoadBitmipImageFromUrl(url, out error);
if (bi == null || !string.IsNullOrEmpty(error))
{
error = "获取图片失败 " + error;
return null;
}
}
catch (Exception e)
{
error = e.Message;
error = "获取图片失败 " + e.Message;
return null;
}
}
try
{
return BitmapImageToSystemDrawingImage(bi);
}
catch (Exception e)
{
error = "转换图片失败 " + e.Message;
return null;
}
}
public static Image BitmapImageToSystemDrawingImage(BitmapImage bitmapImage)
{
@@ -632,10 +647,10 @@ namespace AllBase
Bitmap bitmap = new Bitmap(stream);
stream.Close();
//// 现在你可以将这个Bitmap对象用于Windows Forms的PictureBox或其他图像显示控件
//PictureBox pictureBox = new PictureBox();
//pictureBox.Image = bitmap; // 或者如果你已经有了一个PictureBox控件,直接设置其Image属性
return bitmap;
//// 现在你可以将这个Bitmap对象用于Windows Forms的PictureBox或其他图像显示控件
//PictureBox pictureBox = new PictureBox();
//pictureBox.Image = bitmap; // 或者如果你已经有了一个PictureBox控件,直接设置其Image属性
return bitmap;
}
}