From c525b938afbcca9c2a19cc4a7e2e785c46ae07c9 Mon Sep 17 00:00:00 2001 From: zqm Date: Thu, 30 Oct 2025 14:39:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9InfoImage=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BB=8E=E9=87=8A?= =?UTF-8?q?=E6=94=BE=E8=B5=84=E6=BA=90=E6=94=B9=E4=B8=BA=E7=AE=80=E5=8D=95?= =?UTF-8?q?=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CS/Framework4.0/Toprie/Toprie/Camera.cs | 91 +++++++++++-------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs index 1868c84..b0fe509 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs @@ -81,9 +81,10 @@ namespace JoyD.Windows.CS.Toprie /// /// 更新InfoImage显示 - /// 1. 如果断开,显示重连信息 - /// 2. 否则如果暂停,显示暂停信息 - /// 3. 最后调用更新UI + /// 1. 如果暂停,显示暂停信息 + /// 2. 否则如果Ping不通或断开,显示重连信息 + /// 3. 否则清空InfoImage + /// 4. 最后调用更新UI /// private void UpdateInfo() { @@ -95,17 +96,9 @@ namespace JoyD.Windows.CS.Toprie { lock (_infoImageLock) { - // 释放之前的InfoImage资源 + // 清理InfoImage if (_infoImage != null) { - try - { - _infoImage.Dispose(); - } - catch (Exception ex) - { - Console.WriteLine($"释放InfoImage资源异常: {ex.Message}"); - } _infoImage = null; } @@ -115,9 +108,39 @@ namespace JoyD.Windows.CS.Toprie bool isPaused = _isPaused; // 使用_isPaused标志判断暂停状态 bool isPingFailed = !IsDevicePingable; - // 如果需要显示信息,创建InfoImage - if (isDisconnected || isReconnecting || isPaused || isPingFailed) - { + // 根据用户要求的优先级显示信息:先检查暂停状态,然后再检查Ping状态和连接状态 + if (isPaused) + { + // 暂停状态 - 最高优先级 + _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); + } + + // 绘制暂停文本 + string text = "暂停"; + Color textColor = Color.Red; + + using (Font font = new Font("Arial", 48, FontStyle.Bold)) + using (SolidBrush textBrush = new SolidBrush(textColor)) + { + StringFormat format = new StringFormat(); + format.Alignment = StringAlignment.Center; + + // 将主文本居中显示 + g.DrawString(text, font, textBrush, + new RectangleF(0, BUFFER_HEIGHT / 3, BUFFER_WIDTH, BUFFER_HEIGHT / 3), + format); + } + } + } + else if (isPingFailed || isDisconnected || isReconnecting) + { + // 非暂停状态下,检查Ping状态和连接状态 _infoImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT); using (Graphics g = Graphics.FromImage(_infoImage)) { @@ -131,30 +154,19 @@ namespace JoyD.Windows.CS.Toprie string text = ""; Color textColor = Color.White; - // 根据要求的优先级显示信息:先检查Ping状态和连接状态,最后检查暂停状态 - if (isPingFailed || isDisconnected || isReconnecting) - { - // Ping不通或断开连接状态 - if (isReconnecting) - { - text = "正在重连..."; - textColor = Color.Yellow; - } - else if (isDisconnected) - { - text = "连接断开"; - textColor = Color.Red; - } - else if (isPingFailed) - { - text = "连接断开"; - textColor = Color.Red; - } + if (isReconnecting) + { + text = "正在重连..."; + textColor = Color.Yellow; } - else if (isPaused) - { - // 暂停状态 - text = "暂停"; + else if (isDisconnected) + { + text = "连接断开"; + textColor = Color.Red; + } + else if (isPingFailed) + { + text = "连接断开"; textColor = Color.Red; } @@ -172,9 +184,10 @@ namespace JoyD.Windows.CS.Toprie } } } + // 否则清空InfoImage(已在开头处理) // 设置显示标志 - _isDisplayingInfo = (isDisconnected || isReconnecting || isPaused); + _isDisplayingInfo = (isPaused || isDisconnected || isReconnecting); } // 调用更新UI