显示区域温度
This commit is contained in:
@@ -2927,7 +2927,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. 只有在全局温度模式下才显示温度数据
|
// 6. 根据温度模式显示温度数据
|
||||||
if (isGlobalTemperatureMode)
|
if (isGlobalTemperatureMode)
|
||||||
{
|
{
|
||||||
// 准备温度文本
|
// 准备温度文本
|
||||||
@@ -2961,6 +2961,49 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
// 调用DrawTextInAreaCentered方法绘制温度文本
|
// 调用DrawTextInAreaCentered方法绘制温度文本
|
||||||
DrawTextInAreaCentered(g, textsArray);
|
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像素
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置显示状态标志
|
// 设置显示状态标志
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace JoyD.Windows.CS.Toprie
|
namespace JoyD.Windows.CS.Toprie
|
||||||
@@ -106,8 +104,8 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
// 初始化测温区温度数据和温差数据
|
// 初始化测温区温度数据和温差数据
|
||||||
ZoneTemperatures = new Dictionary<int, ZoneTemperatureData>();
|
ZoneTemperatures = new Dictionary<int, ZoneTemperatureData>();
|
||||||
TemperatureDiffs = new Dictionary<Point, float>();
|
TemperatureDiffs = new Dictionary<Point, float>();
|
||||||
String key = $"{width}_{height}";
|
string key = $"{width}_{height}";
|
||||||
ConcurrentDictionary<String,List<int>> map = _temperatureMap.GetOrAdd(key, new ConcurrentDictionary<string, List<int>>());
|
ConcurrentDictionary<string, List<int>> map = _temperatureMap.GetOrAdd(key, new ConcurrentDictionary<string, List<int>>());
|
||||||
if (map.IsEmpty)
|
if (map.IsEmpty)
|
||||||
{
|
{
|
||||||
// 计算映射比例(从原始分辨率映射到512×384)
|
// 计算映射比例(从原始分辨率映射到512×384)
|
||||||
@@ -152,8 +150,8 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
throw new ArgumentException("数据长度不足,无法解析");
|
throw new ArgumentException("数据长度不足,无法解析");
|
||||||
}
|
}
|
||||||
|
|
||||||
String key = $"{Width}_{Height}";
|
string key = $"{Width}_{Height}";
|
||||||
bool hasMap = _temperatureMap.TryGetValue(key, out ConcurrentDictionary<String, List<int>> map);
|
bool hasMap = _temperatureMap.TryGetValue(key, out ConcurrentDictionary<string, List<int>> map);
|
||||||
// 计算温度数据长度和像素总数
|
// 计算温度数据长度和像素总数
|
||||||
int dataLength = rawData.Length - HEADER_SIZE;
|
int dataLength = rawData.Length - HEADER_SIZE;
|
||||||
int pixelCount = dataLength / 2; // 每个像素2字节
|
int pixelCount = dataLength / 2; // 每个像素2字节
|
||||||
@@ -205,7 +203,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
/// <param name="key">映射键</param>
|
/// <param name="key">映射键</param>
|
||||||
/// <param name="map">映射表</param>
|
/// <param name="map">映射表</param>
|
||||||
/// <param name="temperature">温度值</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;
|
if (!map.TryGetValue(key, out List<int> xy)) return;
|
||||||
for (int idx = 0; idx < xy.Count; idx += 2)
|
for (int idx = 0; idx < xy.Count; idx += 2)
|
||||||
@@ -252,11 +250,11 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
/// <returns>区域温度统计信息</returns>
|
/// <returns>区域温度统计信息</returns>
|
||||||
public RegionTemperatureStats GetRegionStatistics(int startRow, int startCol, int endRow, int endCol)
|
public RegionTemperatureStats GetRegionStatistics(int startRow, int startCol, int endRow, int endCol)
|
||||||
{
|
{
|
||||||
// 参数验证和边界检查
|
// 使用RealTemperatureMatrix的固定尺寸(384x512)进行边界检查
|
||||||
startRow = Math.Max(0, startRow);
|
startRow = Math.Max(0, startRow);
|
||||||
startCol = Math.Max(0, startCol);
|
startCol = Math.Max(0, startCol);
|
||||||
endRow = Math.Min(Height - 1, endRow);
|
endRow = Math.Min(383, endRow); // RealTemperatureMatrix高度为384
|
||||||
endCol = Math.Min(Width - 1, endCol);
|
endCol = Math.Min(511, endCol); // RealTemperatureMatrix宽度为512
|
||||||
|
|
||||||
if (startRow > endRow || startCol > endCol)
|
if (startRow > endRow || startCol > endCol)
|
||||||
return new RegionTemperatureStats(0, 0, 0, 0);
|
return new RegionTemperatureStats(0, 0, 0, 0);
|
||||||
@@ -266,11 +264,12 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
float max = float.MinValue;
|
float max = float.MinValue;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
// 使用RealTemperatureMatrix计算统计值
|
||||||
for (int row = startRow; row <= endRow; row++)
|
for (int row = startRow; row <= endRow; row++)
|
||||||
{
|
{
|
||||||
for (int col = startCol; col <= endCol; col++)
|
for (int col = startCol; col <= endCol; col++)
|
||||||
{
|
{
|
||||||
float temp = TemperatureMatrix[row, col];
|
float temp = RealTemperatureMatrix[row, col];
|
||||||
sum += temp;
|
sum += temp;
|
||||||
min = Math.Min(min, temp);
|
min = Math.Min(min, temp);
|
||||||
max = Math.Max(max, temp);
|
max = Math.Max(max, temp);
|
||||||
@@ -455,7 +454,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 区域温度统计信息
|
/// 区域温度统计信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct RegionTemperatureStats
|
public class RegionTemperatureStats
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 区域最低温度
|
/// 区域最低温度
|
||||||
|
|||||||
Reference in New Issue
Block a user