From 8820857d8aa972dd72f6db5af89fc6ffb344b845 Mon Sep 17 00:00:00 2001 From: zqm Date: Thu, 30 Oct 2025 10:30:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=AD=E5=BC=80=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=92=8C=E9=87=8D=E8=BF=9E=E7=8A=B6=E6=80=81=E7=9A=84?= =?UTF-8?q?InfoImage=E6=98=BE=E7=A4=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CS/Framework4.0/Toprie/Toprie/Camera.cs | 107 +++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs index c327d0a..6cf64a9 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs @@ -808,6 +808,24 @@ namespace JoyD.Windows.CS.Toprie case ConnectionStatus.Connected: Console.WriteLine("设备已连接"); + // 清除InfoImage和显示标志 + lock (_infoImageLock) + { + if (_infoImage != null) + { + try + { + _infoImage.Dispose(); + _infoImage = null; + } + catch (Exception ex) + { + Console.WriteLine($"释放InfoImage资源异常: {ex.Message}"); + } + } + } + _isDisplayingInfo = false; + // 清除错误信息 ShowError(string.Empty); @@ -856,6 +874,48 @@ namespace JoyD.Windows.CS.Toprie } } + // 在InfoImage中显示连接断开信息 + lock (_infoImageLock) + { + // 释放之前的InfoImage资源 + if (_infoImage != null) + { + try + { + _infoImage.Dispose(); + } + catch (Exception ex) + { + Console.WriteLine($"释放InfoImage资源异常: {ex.Message}"); + } + } + + // 创建新的InfoImage并绘制断开连接字样 + _infoImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT); + using (Graphics g = Graphics.FromImage(_infoImage)) + { + // 设置半透明背景 + using (SolidBrush brush = new SolidBrush(Color.FromArgb(128, Color.Black))) + { + g.FillRectangle(brush, 0, 0, BUFFER_WIDTH, BUFFER_HEIGHT); + } + + // 绘制断开连接字样 + using (Font font = new Font("Arial", 36, FontStyle.Bold)) + using (SolidBrush textBrush = new SolidBrush(Color.Red)) + { + StringFormat format = new StringFormat(); + format.Alignment = StringAlignment.Center; + format.LineAlignment = StringAlignment.Center; + g.DrawString("连接断开", font, textBrush, new RectangleF(0, 0, BUFFER_WIDTH, BUFFER_HEIGHT), format); + } + } + } + + // 设置显示信息标志并更新UI + _isDisplayingInfo = true; + UpdateImageOnUI(); + if (!string.IsNullOrEmpty(e.DeviceInfo)) { ShowError(e.DeviceInfo); @@ -866,10 +926,55 @@ namespace JoyD.Windows.CS.Toprie } break; case ConnectionStatus.Connecting: - case ConnectionStatus.Reconnecting: Console.WriteLine($"正在连接设备...{(!string.IsNullOrEmpty(e.DeviceInfo) ? " " + e.DeviceInfo : "")}"); ShowError(string.Empty); // 清除之前的错误信息 break; + case ConnectionStatus.Reconnecting: + Console.WriteLine($"正在重新连接设备...{(!string.IsNullOrEmpty(e.DeviceInfo) ? " " + e.DeviceInfo : "")}"); + ShowError(string.Empty); // 清除之前的错误信息 + + // 在InfoImage中显示正在重连信息 + lock (_infoImageLock) + { + // 释放之前的InfoImage资源 + if (_infoImage != null) + { + try + { + _infoImage.Dispose(); + } + catch (Exception ex) + { + Console.WriteLine($"释放InfoImage资源异常: {ex.Message}"); + } + } + + // 创建新的InfoImage并绘制正在重连字样 + _infoImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT); + using (Graphics g = Graphics.FromImage(_infoImage)) + { + // 设置半透明背景 + using (SolidBrush brush = new SolidBrush(Color.FromArgb(128, Color.Black))) + { + g.FillRectangle(brush, 0, 0, BUFFER_WIDTH, BUFFER_HEIGHT); + } + + // 绘制正在重连字样 + using (Font font = new Font("Arial", 36, FontStyle.Bold)) + using (SolidBrush textBrush = new SolidBrush(Color.Yellow)) + { + StringFormat format = new StringFormat(); + format.Alignment = StringAlignment.Center; + format.LineAlignment = StringAlignment.Center; + g.DrawString("正在重连...", font, textBrush, new RectangleF(0, 0, BUFFER_WIDTH, BUFFER_HEIGHT), format); + } + } + } + + // 设置显示信息标志并更新UI + _isDisplayingInfo = true; + UpdateImageOnUI(); + break; } } catch (Exception ex)