From 82b7c3214743868059bce04302e9ec29642d2e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BC=9F?= Date: Tue, 26 May 2026 11:35:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E9=87=8F=E5=B7=A5=E5=85=B7=E7=BB=84?= =?UTF-8?q?=E7=BA=BF=E5=AE=BD=E6=A0=B9=E6=8D=AE=E5=9B=BE=E5=83=8F=E5=88=86?= =?UTF-8?q?=E8=BE=A8=E7=8E=87=E8=87=AA=E9=80=82=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controls/PolygonRoiCanvas.xaml.cs | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/XP.ImageProcessing.RoiControl/Controls/PolygonRoiCanvas.xaml.cs b/XP.ImageProcessing.RoiControl/Controls/PolygonRoiCanvas.xaml.cs index e046738..ea2f831 100644 --- a/XP.ImageProcessing.RoiControl/Controls/PolygonRoiCanvas.xaml.cs +++ b/XP.ImageProcessing.RoiControl/Controls/PolygonRoiCanvas.xaml.cs @@ -461,6 +461,16 @@ namespace XP.ImageProcessing.RoiControl.Controls #region Measurement + /// + /// 根据画布尺寸计算自适应线宽 + /// + private double GetAdaptiveThickness(double baseThickness = 1.0) + { + double maxDim = Math.Max(CanvasWidth, CanvasHeight); + double scale = Math.Max(1, Math.Round(maxDim / 1000.0)); + return baseThickness * scale; + } + public static readonly DependencyProperty CurrentMeasureModeProperty = DependencyProperty.Register(nameof(CurrentMeasureMode), typeof(Models.MeasureMode), typeof(PolygonRoiCanvas), new PropertyMetadata(Models.MeasureMode.None, OnMeasureModeChanged)); @@ -759,12 +769,12 @@ namespace XP.ImageProcessing.RoiControl.Controls private Models.MeasureGroup CreatePPGroup(Point p1, Point p2) { var g = new Models.MeasureGroup { P1 = p1, P2 = p2 }; - g.Line = new Line { Stroke = Brushes.Lime, StrokeThickness = 1, IsHitTestVisible = false }; + g.Line = new Line { Stroke = Brushes.Lime, StrokeThickness = GetAdaptiveThickness(), IsHitTestVisible = false }; g.Label = new TextBlock { Foreground = Brushes.Yellow, FontSize = 13, FontWeight = FontWeights.Bold, IsHitTestVisible = false }; // 使用垂直线段代替圆点 - g.PerpLine1 = new Line { Stroke = Brushes.Yellow, StrokeThickness = 1, IsHitTestVisible = true, Cursor = Cursors.Hand }; - g.PerpLine2 = new Line { Stroke = Brushes.Yellow, StrokeThickness = 1, IsHitTestVisible = true, Cursor = Cursors.Hand }; + g.PerpLine1 = new Line { Stroke = Brushes.Yellow, StrokeThickness = GetAdaptiveThickness(), IsHitTestVisible = true, Cursor = Cursors.Hand }; + g.PerpLine2 = new Line { Stroke = Brushes.Yellow, StrokeThickness = GetAdaptiveThickness(), IsHitTestVisible = true, Cursor = Cursors.Hand }; // 保留圆点以兼容拖拽逻辑(但设为不可见) g.Dot1 = CreateMDot(Brushes.Red); @@ -866,7 +876,7 @@ namespace XP.ImageProcessing.RoiControl.Controls _ptlTempDot2 = CreateMDot(Brushes.Lime); _measureOverlay.Children.Add(_ptlTempDot2); SetDotPos(_ptlTempDot2, pos); - _ptlTempLine = new Line { Stroke = Brushes.Lime, StrokeThickness = 1, IsHitTestVisible = false, + _ptlTempLine = new Line { Stroke = Brushes.Lime, StrokeThickness = GetAdaptiveThickness(), IsHitTestVisible = false, X1 = _ptlTempL1.Value.X, Y1 = _ptlTempL1.Value.Y, X2 = pos.X, Y2 = pos.Y }; _measureOverlay.Children.Add(_ptlTempLine); RaiseMeasureStatusChanged($"点线距 - 直线已定义,请点击测量点"); @@ -892,10 +902,10 @@ namespace XP.ImageProcessing.RoiControl.Controls private Models.PointToLineGroup CreatePTLGroup(Point l1, Point l2, Point p) { var g = new Models.PointToLineGroup { L1 = l1, L2 = l2, P = p }; - g.MainLine = new Line { Stroke = Brushes.Lime, StrokeThickness = 1, IsHitTestVisible = false }; - g.ExtLine = new Line { Stroke = Brushes.Lime, StrokeThickness = 1, IsHitTestVisible = false, + g.MainLine = new Line { Stroke = Brushes.Lime, StrokeThickness = GetAdaptiveThickness(), IsHitTestVisible = false }; + g.ExtLine = new Line { Stroke = Brushes.Lime, StrokeThickness = GetAdaptiveThickness(), IsHitTestVisible = false, StrokeDashArray = new DoubleCollection { 4, 2 }, Visibility = Visibility.Collapsed }; - g.PerpLine = new Line { Stroke = Brushes.Yellow, StrokeThickness = 1, IsHitTestVisible = false, + g.PerpLine = new Line { Stroke = Brushes.Yellow, StrokeThickness = GetAdaptiveThickness(), IsHitTestVisible = false, StrokeDashArray = new DoubleCollection { 4, 2 } }; g.FootDot = new Ellipse { Width = 2, Height = 2, Fill = Brushes.Cyan, Stroke = Brushes.White, StrokeThickness = 0.5, IsHitTestVisible = false }; g.Label = new TextBlock { Foreground = Brushes.Yellow, FontSize = 13, FontWeight = FontWeights.Bold, IsHitTestVisible = false }; @@ -929,7 +939,7 @@ namespace XP.ImageProcessing.RoiControl.Controls _elfTempLine = new Line { Stroke = Brushes.Cyan, - StrokeThickness = 1, + StrokeThickness = GetAdaptiveThickness(), StrokeDashArray = new DoubleCollection { 4, 2 }, IsHitTestVisible = false, X1 = _elfTempStart.Value.X, @@ -972,7 +982,7 @@ namespace XP.ImageProcessing.RoiControl.Controls _angleTempADot = CreateMDot(Brushes.Orange); _measureOverlay.Children.Add(_angleTempADot); SetDotPos(_angleTempADot, pos); - _angleTempLineA = new Line { Stroke = Brushes.Lime, StrokeThickness = 1, IsHitTestVisible = false, + _angleTempLineA = new Line { Stroke = Brushes.Lime, StrokeThickness = GetAdaptiveThickness(), IsHitTestVisible = false, X1 = _angleTempV.Value.X, Y1 = _angleTempV.Value.Y, X2 = pos.X, Y2 = pos.Y }; _measureOverlay.Children.Add(_angleTempLineA); RaiseMeasureStatusChanged($"角度测量 - 射线A已定义,请点击射线端点B"); @@ -998,9 +1008,9 @@ namespace XP.ImageProcessing.RoiControl.Controls private Models.AngleGroup CreateAngleGroup(Point v, Point a, Point b) { var g = new Models.AngleGroup { V = v, A = a, B = b }; - g.LineA = new Line { Stroke = Brushes.Lime, StrokeThickness = 1, IsHitTestVisible = false }; - g.LineB = new Line { Stroke = Brushes.Lime, StrokeThickness = 1, IsHitTestVisible = false }; - g.Arc = new Path { Stroke = Brushes.Yellow, StrokeThickness = 1.5, IsHitTestVisible = false }; + g.LineA = new Line { Stroke = Brushes.Lime, StrokeThickness = GetAdaptiveThickness(), IsHitTestVisible = false }; + g.LineB = new Line { Stroke = Brushes.Lime, StrokeThickness = GetAdaptiveThickness(), IsHitTestVisible = false }; + g.Arc = new Path { Stroke = Brushes.Yellow, StrokeThickness = GetAdaptiveThickness(1.5), IsHitTestVisible = false }; g.Label = new TextBlock { Foreground = Brushes.Yellow, FontSize = 13, FontWeight = FontWeights.Bold, IsHitTestVisible = false }; g.DotV = CreateMDot(Brushes.Red); g.DotA = CreateMDot(Brushes.Orange); @@ -1041,8 +1051,8 @@ namespace XP.ImageProcessing.RoiControl.Controls g.PathE3 = CreateEllipsePath(Brushes.Yellow, true); g.PathE4 = CreateEllipsePath(Brushes.Lime, false); - g.FullLine = new Line { Stroke = Brushes.Red, StrokeThickness = 1, IsHitTestVisible = false }; - g.FillLine = new Line { Stroke = Brushes.Lime, StrokeThickness = 1, IsHitTestVisible = false }; + g.FullLine = new Line { Stroke = Brushes.Red, StrokeThickness = GetAdaptiveThickness(), IsHitTestVisible = false }; + g.FillLine = new Line { Stroke = Brushes.Lime, StrokeThickness = GetAdaptiveThickness(), IsHitTestVisible = false }; g.Label = new TextBlock { FontSize = 13, FontWeight = FontWeights.Bold, Cursor = Cursors.Hand }; g.Label.SetValue(ContextMenuService.IsEnabledProperty, false); @@ -1079,9 +1089,9 @@ namespace XP.ImageProcessing.RoiControl.Controls return h; } - private static Path CreateEllipsePath(Brush stroke, bool dashed) + private Path CreateEllipsePath(Brush stroke, bool dashed) { - var p = new Path { Stroke = stroke, StrokeThickness = 1.5, IsHitTestVisible = false }; + var p = new Path { Stroke = stroke, StrokeThickness = GetAdaptiveThickness(1.5), IsHitTestVisible = false }; if (dashed) p.StrokeDashArray = new DoubleCollection { 4, 2 }; return p; } @@ -1165,7 +1175,7 @@ namespace XP.ImageProcessing.RoiControl.Controls c.Shape = new Ellipse { Stroke = isBall ? Brushes.Lime : Brushes.Orange, - StrokeThickness = isBall ? 2 : 1.5, + StrokeThickness = isBall ? GetAdaptiveThickness(2) : GetAdaptiveThickness(1.5), Fill = Brushes.Transparent, IsHitTestVisible = false }; @@ -1553,7 +1563,7 @@ namespace XP.ImageProcessing.RoiControl.Controls _bubbleRoiRect = new Rectangle { Stroke = Brushes.Red, - StrokeThickness = 1, + StrokeThickness = GetAdaptiveThickness(), Fill = Brushes.Transparent, Visibility = Visibility.Collapsed, IsHitTestVisible = false @@ -1610,7 +1620,7 @@ namespace XP.ImageProcessing.RoiControl.Controls _bubbleCircleShape = new Ellipse { Stroke = Brushes.Red, - StrokeThickness = 1, + StrokeThickness = GetAdaptiveThickness(), Fill = Brushes.Transparent, Visibility = Visibility.Collapsed, IsHitTestVisible = false @@ -1639,7 +1649,7 @@ namespace XP.ImageProcessing.RoiControl.Controls _bubblePolyShape = new Polygon { Stroke = Brushes.Red, - StrokeThickness = 1, + StrokeThickness = GetAdaptiveThickness(), Fill = Brushes.Transparent, IsHitTestVisible = false };