引入检测区域的概念
This commit is contained in:
@@ -109,6 +109,9 @@ namespace JoyD.Windows.CS.Toprie
|
||||
// 加载的温差配置
|
||||
private TemperatureDiffConfig _loadedTemperatureDiffConfig = new TemperatureDiffConfig();
|
||||
|
||||
// 检测区配置
|
||||
private DetectionZone _detectionZone = new DetectionZone();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置项目路径,控件所需的数据文件将在此目录中进行存取
|
||||
/// </summary>
|
||||
@@ -171,6 +174,18 @@ namespace JoyD.Windows.CS.Toprie
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置检测区配置
|
||||
/// </summary>
|
||||
[Category("配置")]
|
||||
[DisplayName("检测区配置")]
|
||||
[Description("设置检测区的位置和大小")]
|
||||
public DetectionZone CurrentDetectionZone
|
||||
{
|
||||
get { return _detectionZone; }
|
||||
set { _detectionZone = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载测温区配置文件
|
||||
/// </summary>
|
||||
@@ -2375,6 +2390,10 @@ namespace JoyD.Windows.CS.Toprie
|
||||
csvContent.AppendLine($"thermalMode,{thermalModeToolStripMenuItem.Text},{thermalModeToolStripMenuItem.Checked}");
|
||||
if (visibleModeToolStripMenuItem != null)
|
||||
csvContent.AppendLine($"visibleMode,{visibleModeToolStripMenuItem.Text},{visibleModeToolStripMenuItem.Checked}");
|
||||
|
||||
// 保存检测区配置
|
||||
csvContent.AppendLine(); // 添加空行
|
||||
csvContent.AppendLine($"detectionZone,{_detectionZone.X},{_detectionZone.Y},{_detectionZone.Width},{_detectionZone.Height},{_detectionZone.Color.Name}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -2517,6 +2536,31 @@ namespace JoyD.Windows.CS.Toprie
|
||||
if (parts.Length >= 3)
|
||||
{
|
||||
string menuName = parts[0];
|
||||
|
||||
// 检测区配置处理
|
||||
if (menuName == "detectionZone")
|
||||
{
|
||||
if (parts.Length >= 6)
|
||||
{
|
||||
int x = int.Parse(parts[1]);
|
||||
int y = int.Parse(parts[2]);
|
||||
int width = int.Parse(parts[3]);
|
||||
int height = int.Parse(parts[4]);
|
||||
Color color = Color.FromName(parts[5]);
|
||||
|
||||
_detectionZone = new DetectionZone
|
||||
{
|
||||
X = x,
|
||||
Y = y,
|
||||
Width = width,
|
||||
Height = height,
|
||||
Color = color
|
||||
};
|
||||
WriteLog($"成功加载检测区配置: X={x}, Y={y}, Width={width}, Height={height}, Color={color.Name}");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
string status = parts[1];
|
||||
string isChecked = parts[2];
|
||||
|
||||
@@ -2963,18 +3007,22 @@ namespace JoyD.Windows.CS.Toprie
|
||||
// 遍历已加载的测温区列表,绘制每个区域的框线和编号
|
||||
foreach (TemperatureZone zone in _loadedTemperatureZones)
|
||||
{
|
||||
// 将相对坐标转换为绝对坐标
|
||||
int absoluteX = _detectionZone.X + zone.X;
|
||||
int absoluteY = _detectionZone.Y + zone.Y;
|
||||
|
||||
// 创建画笔,使用区域的颜色作为框线颜色
|
||||
using (Pen pen = new Pen(zone.Color, 2))
|
||||
{
|
||||
// 绘制区域框线
|
||||
g.DrawRectangle(pen, zone.X, zone.Y, zone.Width, zone.Height);
|
||||
g.DrawRectangle(pen, absoluteX, absoluteY, zone.Width, zone.Height);
|
||||
}
|
||||
|
||||
// 创建画刷,使用区域的颜色作为文字颜色
|
||||
using (Brush brush = new SolidBrush(zone.Color))
|
||||
{
|
||||
// 绘制区域编号,编号显示在区域左上角
|
||||
PointF numberPosition = new PointF(zone.X + 5, zone.Y + 5);
|
||||
PointF numberPosition = new PointF(absoluteX + 5, absoluteY + 5);
|
||||
g.DrawString(zone.Index.ToString(), font, brush, numberPosition);
|
||||
}
|
||||
}
|
||||
@@ -3245,6 +3293,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
// 显示配置窗口,使用完整命名空间引用Setting类
|
||||
JoyD.Windows.CS.Setting.Form.AutoConfig = this.AutoConfig;
|
||||
JoyD.Windows.CS.Setting.Form.ProjectPath = this.ProjectPath;
|
||||
JoyD.Windows.CS.Setting.Form.CurrentDetectionZone = this.CurrentDetectionZone;
|
||||
JoyD.Windows.CS.Setting.Form.ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -71,6 +71,17 @@ namespace JoyD.Windows.CS
|
||||
// 配置是否已经加载的标志位
|
||||
private bool _isConfigLoaded = false;
|
||||
|
||||
// 检测区配置
|
||||
private DetectionZone _detectionZone = new DetectionZone();
|
||||
/// <summary>
|
||||
/// 获取或设置检测区配置
|
||||
/// </summary>
|
||||
public DetectionZone CurrentDetectionZone
|
||||
{
|
||||
get { return _detectionZone; }
|
||||
set { _detectionZone = value; }
|
||||
}
|
||||
|
||||
// 定时器字段
|
||||
private readonly Timer _timer;
|
||||
|
||||
@@ -2533,6 +2544,32 @@ namespace JoyD.Windows.CS
|
||||
e.Graphics.DrawImage(_rectangleOverlayImage, destRect, 0, 0, _rectangleOverlayImage.Width, _rectangleOverlayImage.Height, GraphicsUnit.Pixel);
|
||||
}
|
||||
|
||||
// 4. 绘制检测区(虚线矩形)
|
||||
if (picBoxTemp.Image != null)
|
||||
{
|
||||
// 计算检测区在控件中的坐标和大小
|
||||
// 创建虚线画笔
|
||||
using (Pen pen = new Pen(Color.Black, 2))
|
||||
{
|
||||
pen.DashStyle = DashStyle.Dash;
|
||||
// 绘制检测区虚线矩形
|
||||
Rectangle destRect = new Rectangle(0, 0, picBoxTemp.ClientSize.Width, picBoxTemp.ClientSize.Height);
|
||||
// 设置绘制质量为无抗锯齿,确保边界清晰
|
||||
e.Graphics.SmoothingMode = SmoothingMode.None;
|
||||
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
|
||||
// 计算检测区在图像中的实际矩形
|
||||
Rectangle detectionRect = new Rectangle(
|
||||
_detectionZone.X,
|
||||
_detectionZone.Y,
|
||||
_detectionZone.Width,
|
||||
_detectionZone.Height);
|
||||
// 将检测区从图像坐标转换为控件坐标
|
||||
Rectangle controlDetectionRect = ImageRectangleToControlRectangle(detectionRect);
|
||||
// 绘制虚线矩形
|
||||
e.Graphics.DrawRectangle(pen, controlDetectionRect);
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制选中区域的半透明填充和八个句柄
|
||||
if (!_isDrawingMode && _selectedRegionIndex != -1)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user