保存配置

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

View File

@@ -59,9 +59,12 @@ namespace Camera
}
public void SetConfigPath(string path)
{
if (_camera != null)
{
_camera.SetConfigPath(path);
}
}
private void InitializeDataGridView()
{
@@ -320,6 +323,7 @@ namespace Camera
{
using (Pen pen = new Pen(Color.Red, 2))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
g.DrawRectangle(pen, scaledDetectionZone);
}
@@ -330,7 +334,6 @@ namespace Camera
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);
}
}
@@ -623,6 +626,8 @@ namespace Camera
if (_isEditingDetectionZone)
{
_isEditingDetectionZone = false;
_isMoving = false;
_isResizing = false;
toolStripButton1.Checked = false;
toolStripButton1.ToolTipText = "修改检测区(点击开启)";
picBoxCamera.Invalidate();
@@ -631,6 +636,8 @@ namespace Camera
if (_isEditingLedZone)
{
_isEditingLedZone = false;
_isMoving = false;
_isResizing = false;
toolStripButton2.Checked = false;
toolStripButton2.ToolTipText = "绘制Led区(点击开启)";
picBoxCamera.Invalidate();
@@ -837,6 +844,7 @@ namespace Camera
{
if (_camera != null)
{
_camera.SaveConfig();
_camera.ImageCaptured -= Camera_ImageCaptured;
}
}