测温区显示时坐标转换

This commit is contained in:
zqm
2026-01-09 15:32:07 +08:00
parent d4049ac891
commit 8c310fc2f0

View File

@@ -5550,7 +5550,6 @@ namespace JoyD.Windows.CS
{ {
// 读取并加载测温区配置 // 读取并加载测温区配置
List<RegionInfo> regions = new List<RegionInfo>(); List<RegionInfo> regions = new List<RegionInfo>();
int regionCounter = 0;
using (StreamReader reader = new StreamReader(configPath, Encoding.UTF8)) using (StreamReader reader = new StreamReader(configPath, Encoding.UTF8))
{ {
@@ -5568,21 +5567,26 @@ namespace JoyD.Windows.CS
if (parts.Length >= 6) if (parts.Length >= 6)
{ {
// 解析数据 // 解析数据
int.TryParse(parts[1], out int x); int.TryParse(parts[0], out int index); // 使用CSV中的索引
int.TryParse(parts[2], out int y); int.TryParse(parts[1], out int x); // 相对坐标
int.TryParse(parts[2], out int y); // 相对坐标
int.TryParse(parts[3], out int width); int.TryParse(parts[3], out int width);
int.TryParse(parts[4], out int height); int.TryParse(parts[4], out int height);
// 将相对坐标转换为绝对坐标(相对于整个图像)
int absoluteX = x + _detectionZone.X;
int absoluteY = y + _detectionZone.Y;
// 兼容两种颜色格式:十六进制颜色代码和颜色名称 // 兼容两种颜色格式:十六进制颜色代码和颜色名称
Color color; Color color;
// 使用通用颜色解析方法,支持颜色名称和十六进制颜色代码 // 使用通用颜色解析方法,支持颜色名称和十六进制颜色代码
color = CommonUtils.ParseColor(parts[5]); color = CommonUtils.ParseColor(parts[5]);
// 创建区域信息 // 创建区域信息(使用绝对坐标)
regions.Add(new RegionInfo regions.Add(new RegionInfo
{ {
Index = ++regionCounter, Index = index, // 使用解析得到的索引
ImageRectangle = new Rectangle(x, y, width, height), ImageRectangle = new Rectangle(absoluteX, absoluteY, width, height),
Color = color Color = color
}); });
} }
@@ -5608,7 +5612,19 @@ namespace JoyD.Windows.CS
// 添加加载的区域 // 添加加载的区域
_drawnRectangles.AddRange(regions); _drawnRectangles.AddRange(regions);
_regionCounter = regions.Count;
// 更新_regionCounter为最大索引值+1以便后续添加新区域
if (regions.Count > 0)
{
_regionCounter = regions.Max(r => r.Index);
}
else
{
_regionCounter = 0;
}
// 同步到原始测温区列表和绝对测温区列表
SyncTemperatureZonesFromDrawnRectangles();
// 创建新的叠加层图像(会绘制所有区域和编号) // 创建新的叠加层图像(会绘制所有区域和编号)
CreateRectangleOverlayImage(); CreateRectangleOverlayImage();
@@ -5732,6 +5748,10 @@ namespace JoyD.Windows.CS
int y = int.Parse(parts[1]); int y = int.Parse(parts[1]);
double temperature = double.Parse(parts[2]); double temperature = double.Parse(parts[2]);
// 保存到原始温差图数据列表(相对于检测区的位置)
Point relativePoint = new Point(x - _detectionZone.X, y - _detectionZone.Y);
_originalTempDiffData[relativePoint] = temperature;
// 找到对应的颜色 - 尝试精确匹配 // 找到对应的颜色 - 尝试精确匹配
Color pixelColor = Color.Transparent; Color pixelColor = Color.Transparent;
if (tempToColorMap.TryGetValue(temperature, out Color exactColor)) if (tempToColorMap.TryGetValue(temperature, out Color exactColor))
@@ -5805,6 +5825,49 @@ namespace JoyD.Windows.CS
dataGridViewTempDiff.Rows.Add(item["tempDiffValue"], ""); dataGridViewTempDiff.Rows.Add(item["tempDiffValue"], "");
} }
// 更新绝对温差图数据
UpdateAbsoluteTempDiffData();
// 重新绘制温差图,确保位置正确
if (_tempDiffOverlayImage != null)
{
// 清除现有温差图
using (Graphics g = Graphics.FromImage(_tempDiffOverlayImage))
{
g.Clear(Color.Transparent);
}
// 根据绝对温差图数据重新绘制
if (_tempDiffOverlayImage is Bitmap bitmap)
{
foreach (KeyValuePair<Point, double> absolutePoint in _absoluteTempDiffData)
{
double temperature = absolutePoint.Value;
// 找到对应的颜色
Color pixelColor = Color.Transparent;
if (tempToColorMap.TryGetValue(temperature, out Color exactColor))
{
pixelColor = exactColor;
}
else
{
// 如果没有精确匹配,尝试四舍五入匹配
double roundedTemp = Math.Round(temperature, 1);
if (tempToColorMap.TryGetValue(roundedTemp, out Color roundedColor))
{
pixelColor = roundedColor;
}
}
if (pixelColor != Color.Transparent)
{
bitmap.SetPixel(absolutePoint.Key.X, absolutePoint.Key.Y, pixelColor);
}
}
}
}
// 刷新显示 // 刷新显示
dataGridViewTempDiff.Refresh(); dataGridViewTempDiff.Refresh();
// 更新温差图显示 // 更新温差图显示