From d7c035518a2b2e70845cc7d65472f52d219994b4 Mon Sep 17 00:00:00 2001 From: zqm Date: Mon, 19 Jan 2026 10:59:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8Preview=E7=AA=97=E5=8F=A3=E4=B8=AD?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BB=A5=E4=B8=8B=E5=8A=9F=E8=83=BD=EF=BC=9A?= =?UTF-8?q?=20-=20=E5=BD=93=E9=BC=A0=E6=A0=87=E6=8C=87=E5=90=91=E7=83=AD?= =?UTF-8?q?=E5=8A=9B=E5=9B=BE=E4=B8=8A=E7=9A=84=E4=BB=BB=E6=84=8F=E7=82=B9?= =?UTF-8?q?=E6=97=B6=20-=20=E6=A0=B9=E6=8D=AE=E9=BC=A0=E6=A0=87=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E8=8E=B7=E5=8F=96=E5=AF=B9=E5=BA=94=E7=9A=84=E6=B8=A9?= =?UTF-8?q?=E8=A1=A5=E5=90=8E=E6=B8=A9=E5=BA=A6=E5=80=BC=20-=20=E5=B0=86?= =?UTF-8?q?=E8=AF=A5=E6=B8=A9=E5=BA=A6=E5=80=BC=E6=98=BE=E7=A4=BA=E5=9C=A8?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E6=A0=87=E9=A2=98=E6=A0=8F=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CS/Framework4.0/Toprie/Toprie/Camera.cs | 2 + .../CS/Framework4.0/Toprie/Toprie/preview.cs | 125 ++++++++++++++++++ 2 files changed, 127 insertions(+) diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs index ec9809a..82f1d14 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs @@ -1329,6 +1329,8 @@ namespace JoyD.Windows.CS.Toprie if (_previewForm != null && !_previewForm.IsDisposed) { _previewForm.UpdateImage(tempImage); + // 传递温度数据给预览窗口 + _previewForm.UpdateTemperatureData(_deviceManager.LastTemperature); } // 步骤5:同步更新检测配置窗口的实时图像属性 // 创建LastImage的副本并通过UpdateRealTimeImage方法传递给Setting窗口 diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/preview.cs b/Windows/CS/Framework4.0/Toprie/Toprie/preview.cs index 5cfd760..ddbd779 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/preview.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/preview.cs @@ -6,6 +6,7 @@ using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; +using JoyD.Windows.CS.Toprie; namespace JoyD.Windows.CS { @@ -25,6 +26,13 @@ namespace JoyD.Windows.CS private Point _currentDataPoint = new Point(-1, -1); // 用于保护_currentDataPoint访问的锁对象 private readonly object _dataPointLock = new object(); + // 最新的温度数据 + private TemperatureData _temperatureData = null; + // 标题栏更新防抖相关字段 + private Timer _titleUpdateTimer = null; + private float _pendingTemperature = float.NaN; + private float _currentDisplayedTemperature = float.NaN; + private const int TITLE_UPDATE_DELAY = 50; // 防抖延迟时间(毫秒) /// /// 初始化预览窗口的构造函数 @@ -35,6 +43,11 @@ namespace JoyD.Windows.CS previewImageBox.MouseMove += PreviewImageBox_MouseMove; previewImageBox.MouseLeave += PreviewImageBox_MouseLeave; previewImageBox.Paint += PreviewImageBox_Paint; + + // 初始化标题栏更新防抖定时器 + _titleUpdateTimer = new Timer(); + _titleUpdateTimer.Interval = TITLE_UPDATE_DELAY; + _titleUpdateTimer.Tick += TitleUpdateTimer_Tick; } /// @@ -73,6 +86,22 @@ namespace JoyD.Windows.CS } } + /// + /// 更新温度数据(线程安全) + /// + /// 温度数据 + public void UpdateTemperatureData(TemperatureData temperatureData) + { + if (this.InvokeRequired) + { + this.Invoke(new Action(UpdateTemperatureData), temperatureData); + return; + } + + // 更新温度数据 + _temperatureData = temperatureData; + } + /// /// 窗口关闭时释放资源 /// @@ -85,6 +114,14 @@ namespace JoyD.Windows.CS previewImageBox.MouseLeave -= PreviewImageBox_MouseLeave; previewImageBox.Paint -= PreviewImageBox_Paint; + // 释放定时器资源 + if (_titleUpdateTimer != null) + { + _titleUpdateTimer.Stop(); + _titleUpdateTimer.Dispose(); + _titleUpdateTimer = null; + } + // 释放图像资源 if (previewImageBox.Image != null) { @@ -92,6 +129,63 @@ namespace JoyD.Windows.CS previewImageBox.Image = null; } } + + // 标题栏更新防抖处理 + private void UpdateTitleBarWithDebounce(float temperature) + { + // 只有当温度值实际变化时才更新 + // 检查NaN情况:如果两者都是NaN,认为没有变化 + if (float.IsNaN(temperature) && float.IsNaN(_currentDisplayedTemperature)) + { + return; // 都是NaN,不需要更新 + } + // 检查数值变化:如果都是有效数字且差异小于阈值,认为没有变化 + if (!float.IsNaN(temperature) && !float.IsNaN(_currentDisplayedTemperature) && + Math.Abs(temperature - _currentDisplayedTemperature) < 0.1f) + { + return; // 温度值没有显著变化,不需要更新 + } + + // 保存待更新的温度值 + _pendingTemperature = temperature; + + // 停止并重新启动定时器 + _titleUpdateTimer.Stop(); + _titleUpdateTimer.Start(); + } + + // 定时器Tick事件,实际更新标题栏 + private void TitleUpdateTimer_Tick(object sender, EventArgs e) + { + // 停止定时器 + _titleUpdateTimer.Stop(); + + // 只有当温度值实际变化时才更新标题栏 + // 检查NaN情况:如果两者都是NaN,认为没有变化 + if (float.IsNaN(_pendingTemperature) && float.IsNaN(_currentDisplayedTemperature)) + { + return; // 都是NaN,不需要更新 + } + // 检查数值变化:如果都是有效数字且差异小于阈值,认为没有变化 + if (!float.IsNaN(_pendingTemperature) && !float.IsNaN(_currentDisplayedTemperature) && + Math.Abs(_pendingTemperature - _currentDisplayedTemperature) < 0.1f) + { + return; // 温度值没有显著变化,不需要更新 + } + + // 更新标题栏 + if (!float.IsNaN(_pendingTemperature)) + { + this.Text = $"预览 - 温度: {_pendingTemperature:F1}°C"; + } + else + { + this.Text = "预览"; + } + + // 更新当前显示的温度值 + _currentDisplayedTemperature = _pendingTemperature; + } // 鼠标移动事件处理 private void PreviewImageBox_MouseMove(object sender, MouseEventArgs e) @@ -112,6 +206,10 @@ namespace JoyD.Windows.CS { _currentDataPoint = dataPoint; previewImageBox.Invalidate(); // 触发Paint事件重绘 + + // 获取温度值并使用防抖机制更新标题栏 + float temperature = GetTemperatureAtDataPoint(dataPoint); + UpdateTitleBarWithDebounce(temperature); } } } @@ -124,6 +222,9 @@ namespace JoyD.Windows.CS { _currentDataPoint = new Point(-1, -1); previewImageBox.Invalidate(); // 触发Paint事件重绘 + + // 使用防抖机制清除标题栏温度显示 + UpdateTitleBarWithDebounce(float.NaN); } } @@ -157,6 +258,30 @@ namespace JoyD.Windows.CS return new Point(x / 2, y / 2); } + // 获取特定数据点的温度值 + private float GetTemperatureAtDataPoint(Point dataPoint) + { + if (_temperatureData == null || _temperatureData.TemperatureMatrix == null) + return float.NaN; + + // 原始数据点(x,y)对应TemperatureMatrix[y][x](TemperatureMatrix是[行][列]结构,已包含温补后的温度数据) + int x = dataPoint.X; + int y = dataPoint.Y; + + // 确保坐标在有效范围内 + // TemperatureMatrix是[行][列]结构,所以: + // - GetLength(0)返回行数 + // - GetLength(1)返回列数 + // - y对应行索引,x对应列索引 + if (x >= 0 && x < _temperatureData.TemperatureMatrix.GetLength(1) && // 列索引有效 + y >= 0 && y < _temperatureData.TemperatureMatrix.GetLength(0)) // 行索引有效 + { + return _temperatureData.TemperatureMatrix[y, x]; // [行][列]访问 + } + + return float.NaN; + } + // 将原始数据点坐标映射到热力图覆盖区域 private Rectangle GetDataPointCoverageArea(Point dataPoint) {