采用相对坐标

This commit is contained in:
zqm
2026-03-26 16:56:26 +08:00
parent 8d0f19927d
commit 821928621a

View File

@@ -716,8 +716,8 @@ namespace Camera
{ {
Rectangle led = _camera.GetLedZone(_currentLedIndex); Rectangle led = _camera.GetLedZone(_currentLedIndex);
scaledLedZone = new Rectangle( scaledLedZone = new Rectangle(
(int)(led.X * scaleX), (int)((detectionZone.X + led.X) * scaleX),
(int)(led.Y * scaleY), (int)((detectionZone.Y + led.Y) * scaleY),
(int)(led.Width * scaleX), (int)(led.Width * scaleX),
(int)(led.Height * scaleY) (int)(led.Height * scaleY)
); );
@@ -1002,14 +1002,13 @@ namespace Camera
{ {
if (_isDrawingLedMode) if (_isDrawingLedMode)
{ {
// 确保是新增LED区而不是修改现有LED区
int newIndex = _camera.GetLedZoneCount() + 1; int newIndex = _camera.GetLedZoneCount() + 1;
// 确保新索引不与现有索引冲突
while (_camera.GetLedZones().ContainsKey(newIndex)) while (_camera.GetLedZones().ContainsKey(newIndex))
{ {
newIndex++; newIndex++;
} }
_camera.AddLedZone(newIndex, new Rectangle(x, y, width, height), Color.Lime); Rectangle detectionZone = _camera.GetDetectionZone();
_camera.AddLedZone(newIndex, new Rectangle(detectionZone.X + x, detectionZone.Y + y, width, height), Color.Lime);
_selectedZoneIndex = newIndex; _selectedZoneIndex = newIndex;
_currentLedIndex = newIndex; _currentLedIndex = newIndex;
_isEditingLedZone = true; _isEditingLedZone = true;
@@ -1141,8 +1140,9 @@ namespace Camera
if (_selectedZoneIndex >= 0 && _camera != null) if (_selectedZoneIndex >= 0 && _camera != null)
{ {
Rectangle zone = _camera.GetLedZone(_selectedZoneIndex); Rectangle zone = _camera.GetLedZone(_selectedZoneIndex);
toolStripNumericUpDown1.Value = zone.X; Rectangle detectionZone = _camera.GetDetectionZone();
toolStripNumericUpDown2.Value = zone.Y; toolStripNumericUpDown1.Value = zone.X - detectionZone.X;
toolStripNumericUpDown2.Value = zone.Y - detectionZone.Y;
toolStripNumericUpDown3.Value = zone.Width; toolStripNumericUpDown3.Value = zone.Width;
toolStripNumericUpDown4.Value = zone.Height; toolStripNumericUpDown4.Value = zone.Height;
} }
@@ -1350,8 +1350,9 @@ namespace Camera
if (_selectedZoneIndex >= 0 && _camera != null) if (_selectedZoneIndex >= 0 && _camera != null)
{ {
Rectangle zone = _camera.GetLedZone(_selectedZoneIndex); Rectangle zone = _camera.GetLedZone(_selectedZoneIndex);
toolStripNumericUpDown1.Value = zone.X; Rectangle detectionZone = _camera.GetDetectionZone();
toolStripNumericUpDown2.Value = zone.Y; toolStripNumericUpDown1.Value = zone.X - detectionZone.X;
toolStripNumericUpDown2.Value = zone.Y - detectionZone.Y;
toolStripNumericUpDown3.Value = zone.Width; toolStripNumericUpDown3.Value = zone.Width;
toolStripNumericUpDown4.Value = zone.Height; toolStripNumericUpDown4.Value = zone.Height;
} }
@@ -1399,7 +1400,8 @@ namespace Camera
int x = (int)toolStripNumericUpDown1.Value; int x = (int)toolStripNumericUpDown1.Value;
Rectangle zone = _camera.GetLedZone(index); Rectangle zone = _camera.GetLedZone(index);
zone.X = x; Rectangle detectionZone = _camera.GetDetectionZone();
zone.X = detectionZone.X + x;
_camera.SetLedZone(index, zone); _camera.SetLedZone(index, zone);
picBoxCamera.Invalidate(); picBoxCamera.Invalidate();
} }
@@ -1412,7 +1414,8 @@ namespace Camera
int y = (int)toolStripNumericUpDown2.Value; int y = (int)toolStripNumericUpDown2.Value;
Rectangle zone = _camera.GetLedZone(index); Rectangle zone = _camera.GetLedZone(index);
zone.Y = y; Rectangle detectionZone = _camera.GetDetectionZone();
zone.Y = detectionZone.Y + y;
_camera.SetLedZone(index, zone); _camera.SetLedZone(index, zone);
picBoxCamera.Invalidate(); picBoxCamera.Invalidate();
} }