保存配置

This commit is contained in:
zqm
2026-03-25 14:16:16 +08:00
parent 481abe11b8
commit f33d70e429
2 changed files with 21 additions and 12 deletions

View File

@@ -103,6 +103,7 @@ namespace Camera
public void SetArea() public void SetArea()
{ {
Setting settingForm = new Setting(); Setting settingForm = new Setting();
settingForm.SetCamera(this);
if (_currentImage != null) if (_currentImage != null)
{ {
settingForm.SetImage(_currentImage); settingForm.SetImage(_currentImage);
@@ -219,10 +220,10 @@ namespace Camera
{ {
if (isDetectionZone) if (isDetectionZone)
{ {
int x = int.Parse(parts[0]); if (!int.TryParse(parts[0], out int x)) continue;
int y = int.Parse(parts[1]); if (!int.TryParse(parts[1], out int y)) continue;
int width = int.Parse(parts[2]); if (!int.TryParse(parts[2], out int width)) continue;
int height = int.Parse(parts[3]); if (!int.TryParse(parts[3], out int height)) continue;
_detectionZone = new Rectangle(x, y, width, height); _detectionZone = new Rectangle(x, y, width, height);
} }
else if (parts[0] == "索引") else if (parts[0] == "索引")
@@ -231,13 +232,13 @@ namespace Camera
} }
else else
{ {
int index = int.Parse(parts[0]); if (!int.TryParse(parts[0], out int index)) continue;
if (index == 1) if (index == 1 && parts.Length >= 5)
{ {
int x = int.Parse(parts[1]); if (!int.TryParse(parts[1], out int x)) continue;
int y = int.Parse(parts[2]); if (!int.TryParse(parts[2], out int y)) continue;
int width = int.Parse(parts[3]); if (!int.TryParse(parts[3], out int width)) continue;
int height = int.Parse(parts[4]); if (!int.TryParse(parts[4], out int height)) continue;
_ledZone = new Rectangle(x, y, width, height); _ledZone = new Rectangle(x, y, width, height);
} }
} }

View File

@@ -60,7 +60,10 @@ namespace Camera
public void SetConfigPath(string path) public void SetConfigPath(string path)
{ {
_camera.SetConfigPath(path); if (_camera != null)
{
_camera.SetConfigPath(path);
}
} }
private void InitializeDataGridView() private void InitializeDataGridView()
@@ -320,6 +323,7 @@ namespace Camera
{ {
using (Pen pen = new Pen(Color.Red, 2)) using (Pen pen = new Pen(Color.Red, 2))
{ {
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
g.DrawRectangle(pen, scaledDetectionZone); g.DrawRectangle(pen, scaledDetectionZone);
} }
@@ -330,7 +334,6 @@ namespace Camera
using (Font font = new Font("Arial", 10)) using (Font font = new Font("Arial", 10))
{ {
g.DrawString("检测区", font, Brushes.Red, scaledDetectionZone.X, scaledDetectionZone.Y - 15);
g.DrawString("Led区", font, Brushes.Green, scaledLedZone.X, scaledLedZone.Y - 15); g.DrawString("Led区", font, Brushes.Green, scaledLedZone.X, scaledLedZone.Y - 15);
} }
} }
@@ -623,6 +626,8 @@ namespace Camera
if (_isEditingDetectionZone) if (_isEditingDetectionZone)
{ {
_isEditingDetectionZone = false; _isEditingDetectionZone = false;
_isMoving = false;
_isResizing = false;
toolStripButton1.Checked = false; toolStripButton1.Checked = false;
toolStripButton1.ToolTipText = "修改检测区(点击开启)"; toolStripButton1.ToolTipText = "修改检测区(点击开启)";
picBoxCamera.Invalidate(); picBoxCamera.Invalidate();
@@ -631,6 +636,8 @@ namespace Camera
if (_isEditingLedZone) if (_isEditingLedZone)
{ {
_isEditingLedZone = false; _isEditingLedZone = false;
_isMoving = false;
_isResizing = false;
toolStripButton2.Checked = false; toolStripButton2.Checked = false;
toolStripButton2.ToolTipText = "绘制Led区(点击开启)"; toolStripButton2.ToolTipText = "绘制Led区(点击开启)";
picBoxCamera.Invalidate(); picBoxCamera.Invalidate();
@@ -837,6 +844,7 @@ namespace Camera
{ {
if (_camera != null) if (_camera != null)
{ {
_camera.SaveConfig();
_camera.ImageCaptured -= Camera_ImageCaptured; _camera.ImageCaptured -= Camera_ImageCaptured;
} }
} }