diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs index 527e678..15028d4 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs @@ -2927,7 +2927,7 @@ namespace JoyD.Windows.CS.Toprie } } - // 6. 只有在全局温度模式下才显示温度数据 + // 6. 根据温度模式显示温度数据 if (isGlobalTemperatureMode) { // 准备温度文本 @@ -2961,6 +2961,49 @@ namespace JoyD.Windows.CS.Toprie // 调用DrawTextInAreaCentered方法绘制温度文本 DrawTextInAreaCentered(g, textsArray); } + else if (_showAreaTemperature) + { + // 区域温度模式:为每个区域计算并显示温度数据 + using (Font font = new Font("微软雅黑", 10, FontStyle.Bold)) + { + // 遍历已加载的测温区列表,为每个区域显示温度数据 + foreach (TemperatureZone zone in _loadedTemperatureZones) + { + // 准备温度文本 + List areaTemperatureTexts = new List(); + + // 直接从ZoneTemperatures字典获取已计算好的区域温度数据 + if (temperatureData.ZoneTemperatures.TryGetValue(zone.Index, out var zoneTempData)) + { + if (_showMaxTemperature) + { + areaTemperatureTexts.Add($"最高: {zoneTempData.MaxTemperature:F2} °C"); + } + if (_showMinTemperature) + { + areaTemperatureTexts.Add($"最低: {zoneTempData.MinTemperature:F2} °C"); + } + if (_showAverageTemperature) + { + areaTemperatureTexts.Add($"平均: {zoneTempData.AverageTemperature:F2} °C"); + } + } + + // 创建画刷,使用区域的颜色作为文字颜色 + using (Brush brush = new SolidBrush(zone.Color)) + { + // 绘制温度文本,从区域左上角开始,向下排列 + float currentY = zone.Y + 20; // 从区域编号下方开始 + foreach (string text in areaTemperatureTexts) + { + PointF textPosition = new PointF(zone.X + 5, currentY); + g.DrawString(text, font, brush, textPosition); + currentY += 20; // 每行间隔20像素 + } + } + } + } + } } // 设置显示状态标志 diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/TemperatureData.cs b/Windows/CS/Framework4.0/Toprie/Toprie/TemperatureData.cs index be57fbd..c3065ab 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/TemperatureData.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/TemperatureData.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.Concurrent; -using System.Linq; using System.Text; -using System.Threading.Tasks; using System.Drawing; namespace JoyD.Windows.CS.Toprie @@ -106,8 +104,8 @@ namespace JoyD.Windows.CS.Toprie // 初始化测温区温度数据和温差数据 ZoneTemperatures = new Dictionary(); TemperatureDiffs = new Dictionary(); - String key = $"{width}_{height}"; - ConcurrentDictionary> map = _temperatureMap.GetOrAdd(key, new ConcurrentDictionary>()); + string key = $"{width}_{height}"; + ConcurrentDictionary> map = _temperatureMap.GetOrAdd(key, new ConcurrentDictionary>()); if (map.IsEmpty) { // 计算映射比例(从原始分辨率映射到512×384) @@ -152,8 +150,8 @@ namespace JoyD.Windows.CS.Toprie throw new ArgumentException("数据长度不足,无法解析"); } - String key = $"{Width}_{Height}"; - bool hasMap = _temperatureMap.TryGetValue(key, out ConcurrentDictionary> map); + string key = $"{Width}_{Height}"; + bool hasMap = _temperatureMap.TryGetValue(key, out ConcurrentDictionary> map); // 计算温度数据长度和像素总数 int dataLength = rawData.Length - HEADER_SIZE; int pixelCount = dataLength / 2; // 每个像素2字节 @@ -205,7 +203,7 @@ namespace JoyD.Windows.CS.Toprie /// 映射键 /// 映射表 /// 温度值 - private void MapToRealTemperatureMatrix(String key, ConcurrentDictionary> map, float temperature) + private void MapToRealTemperatureMatrix(string key, ConcurrentDictionary> map, float temperature) { if (!map.TryGetValue(key, out List xy)) return; for (int idx = 0; idx < xy.Count; idx += 2) @@ -252,11 +250,11 @@ namespace JoyD.Windows.CS.Toprie /// 区域温度统计信息 public RegionTemperatureStats GetRegionStatistics(int startRow, int startCol, int endRow, int endCol) { - // 参数验证和边界检查 + // 使用RealTemperatureMatrix的固定尺寸(384x512)进行边界检查 startRow = Math.Max(0, startRow); startCol = Math.Max(0, startCol); - endRow = Math.Min(Height - 1, endRow); - endCol = Math.Min(Width - 1, endCol); + endRow = Math.Min(383, endRow); // RealTemperatureMatrix高度为384 + endCol = Math.Min(511, endCol); // RealTemperatureMatrix宽度为512 if (startRow > endRow || startCol > endCol) return new RegionTemperatureStats(0, 0, 0, 0); @@ -266,11 +264,12 @@ namespace JoyD.Windows.CS.Toprie float max = float.MinValue; int count = 0; + // 使用RealTemperatureMatrix计算统计值 for (int row = startRow; row <= endRow; row++) { for (int col = startCol; col <= endCol; col++) { - float temp = TemperatureMatrix[row, col]; + float temp = RealTemperatureMatrix[row, col]; sum += temp; min = Math.Min(min, temp); max = Math.Max(max, temp); @@ -455,7 +454,7 @@ namespace JoyD.Windows.CS.Toprie /// /// 区域温度统计信息 /// - public struct RegionTemperatureStats + public class RegionTemperatureStats { /// /// 区域最低温度