显示区域温度

This commit is contained in:
zqm
2026-01-04 14:03:32 +08:00
parent d048d0af8a
commit 877ead1637
2 changed files with 55 additions and 13 deletions

View File

@@ -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<string> areaTemperatureTexts = new List<string>();
// 直接从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像素
}
}
}
}
}
}
// 设置显示状态标志

View File

@@ -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<int, ZoneTemperatureData>();
TemperatureDiffs = new Dictionary<Point, float>();
String key = $"{width}_{height}";
ConcurrentDictionary<String,List<int>> map = _temperatureMap.GetOrAdd(key, new ConcurrentDictionary<string, List<int>>());
string key = $"{width}_{height}";
ConcurrentDictionary<string, List<int>> map = _temperatureMap.GetOrAdd(key, new ConcurrentDictionary<string, List<int>>());
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<String, List<int>> map);
string key = $"{Width}_{Height}";
bool hasMap = _temperatureMap.TryGetValue(key, out ConcurrentDictionary<string, List<int>> map);
// 计算温度数据长度和像素总数
int dataLength = rawData.Length - HEADER_SIZE;
int pixelCount = dataLength / 2; // 每个像素2字节
@@ -205,7 +203,7 @@ namespace JoyD.Windows.CS.Toprie
/// <param name="key">映射键</param>
/// <param name="map">映射表</param>
/// <param name="temperature">温度值</param>
private void MapToRealTemperatureMatrix(String key, ConcurrentDictionary<String, List<int>> map, float temperature)
private void MapToRealTemperatureMatrix(string key, ConcurrentDictionary<string, List<int>> map, float temperature)
{
if (!map.TryGetValue(key, out List<int> xy)) return;
for (int idx = 0; idx < xy.Count; idx += 2)
@@ -252,11 +250,11 @@ namespace JoyD.Windows.CS.Toprie
/// <returns>区域温度统计信息</returns>
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
/// <summary>
/// 区域温度统计信息
/// </summary>
public struct RegionTemperatureStats
public class RegionTemperatureStats
{
/// <summary>
/// 区域最低温度