0

我目前正在开发一种允许在不同窗口中打开多个图像的工具。主要目标是能够分别移动/调整表单和图像的大小。这是一个非常简单的表单,包含一个边框,包含一个图像。我可以使用变换组平移和缩放图像,一切正常。

我的问题是,如果我将窗口调整为比图像更小的尺寸,然后将图像移动到窗口内,则调整大小后不可见的部分图像被裁剪,并且只能在调整窗口大小时检索本身。以同样的方式,如果我减小图像大小然后减小窗口大小,图像将被裁剪。

所以我想知道是什么因素导致了这种行为,有没有办法摆脱它?要么首先要求表单不要裁剪图像,要么在翻译时重绘它?

XAML

<Window x:Class="Toolboxproto.imgWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="imgWindow" Height="300" Width="300"
    ShowInTaskbar="False"
    WindowStyle="None" 
    MouseLeftButtonDown="Window_MouseLeftButtonDown" 
    Activated="Window_Activated" 
    SizeChanged="Window_SizeChanged" 
    ResizeMode="CanResizeWithGrip" MouseWheel="Window_MouseWheel"
    >

<Border x:Name="border" ClipToBounds="True" Background="Gray" >
 <Image x:Name="image" 
  HorizontalAlignment="Center" 
  Height="290" 
  VerticalAlignment="Center" 
  Width="290" 
  MouseLeftButtonDown="image_MouseLeftButtonDown" 
  MouseWheel="image_MouseWheel" 
  MouseMove="image_MouseMove" 
  MouseLeftButtonUp="image_MouseLeftButtonUp" 
/>

截图

编辑:如果相关,这是图像翻译和缩放的代码:

private void image_MouseWheel(object sender, MouseWheelEventArgs e)
    {
        if (Keyboard.IsKeyDown(Key.LeftCtrl))
        {

            double zoom = e.Delta > 0 ? 0.1 : -0.1;
            if ((e.Delta < 0) && (scaleT.ScaleX < 0.2 || scaleT.ScaleY < 0.2))
            { return; }


            Point relative = e.GetPosition(image);
            //Point absolute = new Point(0,0);

            double absoluteX = relative.X * scaleT.ScaleX + translateT.X;
            double absoluteY = relative.Y * scaleT.ScaleY + translateT.Y;

            scaleT.ScaleX += zoom;
            scaleT.ScaleY += zoom;

            translateT.X = absoluteX - relative.X * scaleT.ScaleX;
            translateT.Y = absoluteY - relative.Y * scaleT.ScaleY;
        }
}

 private void image_MouseMove(object sender, MouseEventArgs e)
    {

        if (image.IsMouseCaptured)
        {


            translateT.X = origin.X - (start.X - e.GetPosition(border).X);
            translateT.Y = origin.Y - (start.Y - e.GetPosition(border).Y);


        }

    }
4

0 回答 0