优化上传商品图片

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;
}
}
+109 -106
View File
@@ -40,6 +40,7 @@ namespace TemuKJD.WXForms.ProductForms
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.ucGroupBoxEx2 = new TemuKJD.UserComponent.UcGroupBoxEx(this.components);
this.btnClearAll = new DevComponents.DotNetBar.PanelEx();
@@ -242,6 +243,10 @@ namespace TemuKJD.WXForms.ProductForms
this.txtSinglePriceAdd = new System.Windows.Forms.TextBox();
this.chkTestNoAuditUpload = new TemuKJD.UserComponent.UcCheckBox(this.components);
this.dgvSelectProduct = new TemuKJD.UserComponent.DataGridViewEx();
this.splitContainer4 = new System.Windows.Forms.SplitContainer();
this.statusBar = new TemuKJD.UserControls.StatusBarUserControl();
this.btnClear = new DevComponents.DotNetBar.PanelEx();
this.panelEx1 = new DevComponents.DotNetBar.PanelEx();
this.colCheck = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.colSelectId = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colSupplierId = new System.Windows.Forms.DataGridViewTextBoxColumn();
@@ -264,10 +269,6 @@ namespace TemuKJD.WXForms.ProductForms
this.ColDelete = new System.Windows.Forms.DataGridViewLinkColumn();
this.colAddTime = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colOpResult = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.splitContainer4 = new System.Windows.Forms.SplitContainer();
this.statusBar = new TemuKJD.UserControls.StatusBarUserControl();
this.btnClear = new DevComponents.DotNetBar.PanelEx();
this.panelEx1 = new DevComponents.DotNetBar.PanelEx();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
@@ -3200,6 +3201,86 @@ namespace TemuKJD.WXForms.ProductForms
this.dgvSelectProduct.TabIndex = 187;
this.dgvSelectProduct.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvSelectProduct_CellContentClick);
//
// splitContainer4
//
this.splitContainer4.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer4.FixedPanel = System.Windows.Forms.FixedPanel.Panel2;
this.splitContainer4.Location = new System.Drawing.Point(0, 0);
this.splitContainer4.Name = "splitContainer4";
//
// splitContainer4.Panel1
//
this.splitContainer4.Panel1.Controls.Add(this.statusBar);
//
// splitContainer4.Panel2
//
this.splitContainer4.Panel2.Controls.Add(this.btnClear);
this.splitContainer4.Panel2.Controls.Add(this.panelEx1);
this.splitContainer4.Size = new System.Drawing.Size(1710, 25);
this.splitContainer4.SplitterDistance = 1019;
this.splitContainer4.TabIndex = 3;
//
// statusBar
//
this.statusBar.BackColor = System.Drawing.Color.White;
this.statusBar.Dock = System.Windows.Forms.DockStyle.Fill;
this.statusBar.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.statusBar.Location = new System.Drawing.Point(0, 0);
this.statusBar.Margin = new System.Windows.Forms.Padding(0);
this.statusBar.Name = "statusBar";
this.statusBar.Size = new System.Drawing.Size(1019, 25);
this.statusBar.TabIndex = 2;
//
// btnClear
//
this.btnClear.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.btnClear.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
this.btnClear.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnClear.DisabledBackColor = System.Drawing.Color.Empty;
this.btnClear.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnClear.Location = new System.Drawing.Point(475, 1);
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(90, 21);
this.btnClear.Style.Alignment = System.Drawing.StringAlignment.Center;
this.btnClear.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
this.btnClear.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
this.btnClear.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder;
this.btnClear.Style.BorderDashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
this.btnClear.Style.BorderSide = DevComponents.DotNetBar.eBorderSide.None;
this.btnClear.Style.ForeColor.Color = System.Drawing.Color.White;
this.btnClear.Style.GradientAngle = 90;
this.btnClear.StyleMouseOver.Alignment = System.Drawing.StringAlignment.Center;
this.btnClear.StyleMouseOver.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255)))));
this.btnClear.StyleMouseOver.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255)))));
this.btnClear.StyleMouseOver.ForeColor.Color = System.Drawing.Color.White;
this.btnClear.TabIndex = 440;
this.btnClear.Text = "清空结果";
this.btnClear.Visible = false;
//
// panelEx1
//
this.panelEx1.CanvasColor = System.Drawing.SystemColors.Control;
this.panelEx1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
this.panelEx1.DisabledBackColor = System.Drawing.Color.Empty;
this.panelEx1.Location = new System.Drawing.Point(568, 2);
this.panelEx1.Name = "panelEx1";
this.panelEx1.Size = new System.Drawing.Size(115, 21);
this.panelEx1.Style.Alignment = System.Drawing.StringAlignment.Center;
this.panelEx1.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(185)))), ((int)(((byte)(215)))), ((int)(((byte)(255)))));
this.panelEx1.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(185)))), ((int)(((byte)(215)))), ((int)(((byte)(255)))));
this.panelEx1.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine;
this.panelEx1.Style.BorderColor.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
this.panelEx1.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText;
this.panelEx1.Style.GradientAngle = 90;
this.panelEx1.StyleMouseDown.Alignment = System.Drawing.StringAlignment.Center;
this.panelEx1.StyleMouseOver.Alignment = System.Drawing.StringAlignment.Center;
this.panelEx1.StyleMouseOver.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
this.panelEx1.StyleMouseOver.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
this.panelEx1.StyleMouseOver.ForeColor.Color = System.Drawing.Color.White;
this.panelEx1.TabIndex = 668;
this.panelEx1.Text = "停止当前操作";
this.panelEx1.Visible = false;
//
// colCheck
//
this.colCheck.Frozen = true;
@@ -3382,91 +3463,13 @@ namespace TemuKJD.WXForms.ProductForms
//
// colOpResult
//
dataGridViewCellStyle9.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.colOpResult.DefaultCellStyle = dataGridViewCellStyle9;
this.colOpResult.HeaderText = "操作结果";
this.colOpResult.Name = "colOpResult";
this.colOpResult.ReadOnly = true;
this.colOpResult.Width = 280;
//
// splitContainer4
//
this.splitContainer4.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer4.FixedPanel = System.Windows.Forms.FixedPanel.Panel2;
this.splitContainer4.Location = new System.Drawing.Point(0, 0);
this.splitContainer4.Name = "splitContainer4";
//
// splitContainer4.Panel1
//
this.splitContainer4.Panel1.Controls.Add(this.statusBar);
//
// splitContainer4.Panel2
//
this.splitContainer4.Panel2.Controls.Add(this.btnClear);
this.splitContainer4.Panel2.Controls.Add(this.panelEx1);
this.splitContainer4.Size = new System.Drawing.Size(1710, 25);
this.splitContainer4.SplitterDistance = 1019;
this.splitContainer4.TabIndex = 3;
//
// statusBar
//
this.statusBar.BackColor = System.Drawing.Color.White;
this.statusBar.Dock = System.Windows.Forms.DockStyle.Fill;
this.statusBar.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.statusBar.Location = new System.Drawing.Point(0, 0);
this.statusBar.Margin = new System.Windows.Forms.Padding(0);
this.statusBar.Name = "statusBar";
this.statusBar.Size = new System.Drawing.Size(1019, 25);
this.statusBar.TabIndex = 2;
//
// btnClear
//
this.btnClear.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.btnClear.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
this.btnClear.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnClear.DisabledBackColor = System.Drawing.Color.Empty;
this.btnClear.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnClear.Location = new System.Drawing.Point(475, 1);
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(90, 21);
this.btnClear.Style.Alignment = System.Drawing.StringAlignment.Center;
this.btnClear.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
this.btnClear.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
this.btnClear.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder;
this.btnClear.Style.BorderDashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
this.btnClear.Style.BorderSide = DevComponents.DotNetBar.eBorderSide.None;
this.btnClear.Style.ForeColor.Color = System.Drawing.Color.White;
this.btnClear.Style.GradientAngle = 90;
this.btnClear.StyleMouseOver.Alignment = System.Drawing.StringAlignment.Center;
this.btnClear.StyleMouseOver.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255)))));
this.btnClear.StyleMouseOver.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255)))));
this.btnClear.StyleMouseOver.ForeColor.Color = System.Drawing.Color.White;
this.btnClear.TabIndex = 440;
this.btnClear.Text = "清空结果";
this.btnClear.Visible = false;
//
// panelEx1
//
this.panelEx1.CanvasColor = System.Drawing.SystemColors.Control;
this.panelEx1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
this.panelEx1.DisabledBackColor = System.Drawing.Color.Empty;
this.panelEx1.Location = new System.Drawing.Point(568, 2);
this.panelEx1.Name = "panelEx1";
this.panelEx1.Size = new System.Drawing.Size(115, 21);
this.panelEx1.Style.Alignment = System.Drawing.StringAlignment.Center;
this.panelEx1.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(185)))), ((int)(((byte)(215)))), ((int)(((byte)(255)))));
this.panelEx1.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(185)))), ((int)(((byte)(215)))), ((int)(((byte)(255)))));
this.panelEx1.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine;
this.panelEx1.Style.BorderColor.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
this.panelEx1.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText;
this.panelEx1.Style.GradientAngle = 90;
this.panelEx1.StyleMouseDown.Alignment = System.Drawing.StringAlignment.Center;
this.panelEx1.StyleMouseOver.Alignment = System.Drawing.StringAlignment.Center;
this.panelEx1.StyleMouseOver.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
this.panelEx1.StyleMouseOver.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
this.panelEx1.StyleMouseOver.ForeColor.Color = System.Drawing.Color.White;
this.panelEx1.TabIndex = 668;
this.panelEx1.Text = "停止当前操作";
this.panelEx1.Visible = false;
//
// WXDBProdUploadForm
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
@@ -3664,28 +3667,6 @@ namespace TemuKJD.WXForms.ProductForms
private System.Windows.Forms.DataGridViewTextBoxColumn colOnSaleNum;
private System.Windows.Forms.DataGridViewTextBoxColumn colRemaining;
private System.Windows.Forms.DataGridViewTextBoxColumn colMessage;
private System.Windows.Forms.DataGridViewCheckBoxColumn colCheck;
private System.Windows.Forms.DataGridViewTextBoxColumn colSelectId;
private System.Windows.Forms.DataGridViewTextBoxColumn colSupplierId;
private System.Windows.Forms.DataGridViewTextBoxColumn colSupplierName;
private System.Windows.Forms.DataGridViewLinkColumn colLogin;
private System.Windows.Forms.DataGridViewLinkColumn colInShop;
private System.Windows.Forms.DataGridViewLinkColumn colSpuId;
private System.Windows.Forms.DataGridViewLinkColumn colSkcId;
private System.Windows.Forms.DataGridViewTextBoxColumn colImgUrl;
private System.Windows.Forms.DataGridViewImageColumn colProductSkcPic;
private System.Windows.Forms.DataGridViewTextBoxColumn colSkuFakeImgUrl;
private System.Windows.Forms.DataGridViewImageColumn colSkuFakeImg;
private System.Windows.Forms.DataGridViewTextBoxColumn colProductName;
private System.Windows.Forms.DataGridViewTextBoxColumn colProductCat;
private System.Windows.Forms.DataGridViewTextBoxColumn colExtCode;
private System.Windows.Forms.DataGridViewTextBoxColumn colMsg;
private System.Windows.Forms.DataGridViewTextBoxColumn colDraftId;
private System.Windows.Forms.DataGridViewTextBoxColumn colNotes;
private System.Windows.Forms.DataGridViewLinkColumn colUserNotes;
private System.Windows.Forms.DataGridViewLinkColumn ColDelete;
private System.Windows.Forms.DataGridViewTextBoxColumn colAddTime;
private System.Windows.Forms.DataGridViewTextBoxColumn colOpResult;
private System.Windows.Forms.Label label25;
private System.Windows.Forms.TextBox txtDefaultBestBefore;
private UserComponent.UcCheckBox chkDefaultBestBefore;
@@ -3764,5 +3745,27 @@ namespace TemuKJD.WXForms.ProductForms
private System.Windows.Forms.Label label43;
private System.Windows.Forms.NumericUpDown numNotUploadShopProdMoreThan;
private UserComponent.UcCheckBox chkNotUploadShopProdMoreThan;
private System.Windows.Forms.DataGridViewCheckBoxColumn colCheck;
private System.Windows.Forms.DataGridViewTextBoxColumn colSelectId;
private System.Windows.Forms.DataGridViewTextBoxColumn colSupplierId;
private System.Windows.Forms.DataGridViewTextBoxColumn colSupplierName;
private System.Windows.Forms.DataGridViewLinkColumn colLogin;
private System.Windows.Forms.DataGridViewLinkColumn colInShop;
private System.Windows.Forms.DataGridViewLinkColumn colSpuId;
private System.Windows.Forms.DataGridViewLinkColumn colSkcId;
private System.Windows.Forms.DataGridViewTextBoxColumn colImgUrl;
private System.Windows.Forms.DataGridViewImageColumn colProductSkcPic;
private System.Windows.Forms.DataGridViewTextBoxColumn colSkuFakeImgUrl;
private System.Windows.Forms.DataGridViewImageColumn colSkuFakeImg;
private System.Windows.Forms.DataGridViewTextBoxColumn colProductName;
private System.Windows.Forms.DataGridViewTextBoxColumn colProductCat;
private System.Windows.Forms.DataGridViewTextBoxColumn colExtCode;
private System.Windows.Forms.DataGridViewTextBoxColumn colMsg;
private System.Windows.Forms.DataGridViewTextBoxColumn colDraftId;
private System.Windows.Forms.DataGridViewTextBoxColumn colNotes;
private System.Windows.Forms.DataGridViewLinkColumn colUserNotes;
private System.Windows.Forms.DataGridViewLinkColumn ColDelete;
private System.Windows.Forms.DataGridViewTextBoxColumn colAddTime;
private System.Windows.Forms.DataGridViewTextBoxColumn colOpResult;
}
}
@@ -6235,6 +6235,8 @@ namespace TemuKJD.WXForms.ProductForms
//生成主图base64字符串
string getImgError;
//if (!img_url.Contains("wst.wxapp.tc.qq.com") && !img_url.Contains("mmecimage.cn"))
//优选靓键店 登录 进店 397652670 重庆川味百年传奇山椒笋尖低脂解馋泡椒脆笋脆嫩爽口开胃解腻追剧办公解馋休闲小零食独立小包装 547009 371857150 0 初始化图片上传失败 值不能为 null。
//参数名: source https://wst.wxapp.tc.qq.com/161/20304/snscosdownload/SH/reserved/6acd9a520004f3272b49791884351f15000000a100004f50 14秒
if (!img_url.Contains("wxapp") && !img_url.Contains("mmecimage.cn"))
img_url = img_url.Replace("https://", "http://");
var image = GetHtml.GetUrlImg(img_url, out getImgError);