去掉图像显示区的放大、缩小、适应按钮;改为鼠标右键弹出选择菜单

This commit is contained in:
李伟
2026-04-23 16:15:52 +08:00
parent 3e337cf04f
commit 3aa64843c8
2 changed files with 20 additions and 45 deletions
@@ -124,6 +124,8 @@ namespace XP.ImageProcessing.RoiControl.Controls
{
control.CanvasWidth = imageSource.Width;
control.CanvasHeight = imageSource.Height;
// 图像加载后自动适应窗口居中显示
control.ResetView();
}
}
@@ -334,39 +336,15 @@ namespace XP.ImageProcessing.RoiControl.Controls
private void Canvas_MouseWheel(object sender, MouseWheelEventArgs e)
{
// 获取鼠标在 imageDisplayGrid 中的位置
Point mousePos = e.GetPosition(imageDisplayGrid);
// 获取鼠标在 Canvas 中的位置(缩放前)
Point mousePosOnCanvas = e.GetPosition(mainCanvas);
double oldZoom = ZoomScale;
double newZoom = oldZoom;
if (e.Delta > 0)
{
newZoom = oldZoom * ZoomStep;
}
else
{
newZoom = oldZoom / ZoomStep;
}
// 限制缩放范围
double newZoom = e.Delta > 0 ? oldZoom * ZoomStep : oldZoom / ZoomStep;
newZoom = Math.Max(0.1, Math.Min(10.0, newZoom));
if (Math.Abs(newZoom - oldZoom) > 0.001)
{
// 计算缩放比例变化
double scale = newZoom / oldZoom;
// 更新缩放
ZoomScale = newZoom;
// 调整平移偏移,使鼠标位置保持不变
// 新的偏移 = 旧偏移 + 鼠标位置 - 鼠标位置 * 缩放比例
PanOffsetX = mousePos.X - (mousePos.X - PanOffsetX) * scale;
PanOffsetY = mousePos.Y - (mousePos.Y - PanOffsetY) * scale;
// RenderTransformOrigin="0.5,0.5" 保证以图像中心等比缩放
// 拖拽平移偏移保持不变
}
e.Handled = true;
@@ -414,7 +392,7 @@ namespace XP.ImageProcessing.RoiControl.Controls
{
// 右键点击完成多边形
OnRightClick();
e.Handled = true;
// 不设 e.Handled,让 ContextMenu 正常弹出
}
private void ROI_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
@@ -470,6 +448,8 @@ namespace XP.ImageProcessing.RoiControl.Controls
if (newZoom <= 10.0)
{
ZoomScale = newZoom;
PanOffsetX = 0;
PanOffsetY = 0;
}
}
@@ -479,6 +459,8 @@ namespace XP.ImageProcessing.RoiControl.Controls
if (newZoom >= 0.1)
{
ZoomScale = newZoom;
PanOffsetX = 0;
PanOffsetY = 0;
}
}