Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 像谷歌地图一样的图像运动_C#_Wpf_Image_Move_Panning - Fatal编程技术网

C# 像谷歌地图一样的图像运动

C# 像谷歌地图一样的图像运动,c#,wpf,image,move,panning,C#,Wpf,Image,Move,Panning,我有一个大的图像,我需要在一个较小的容器中显示(或像这样的smthg)。用户应该能够上下左右移动图像。它应该像谷歌地图一样 你知道我从哪里开始以及如何解决这个问题吗?也许类似的方法会奏效 您还可以创建具有平移功能的简单UserControl或CustomControl,例如,使用一个画布处理一些鼠标事件,以操纵图像上的TranslateTransform,它应该是画布的子级 事件处理大纲: // Add this transform to the image as RenderTransfor

我有一个大的图像,我需要在一个较小的容器中显示(或像这样的smthg)。用户应该能够上下左右移动图像。它应该像谷歌地图一样

你知道我从哪里开始以及如何解决这个问题吗?

也许类似的方法会奏效


您还可以创建具有平移功能的简单UserControl或CustomControl,例如,使用一个画布处理一些鼠标事件,以操纵图像上的TranslateTransform,它应该是画布的子级

事件处理大纲:

// Add this transform to the image as RenderTransform
private TranslateTransform _translateT = new TranslateTransform();
private Point _lastMousePos = new Point();

private void This_MouseDown(object sender, MouseButtonEventArgs 
{
    if (e.ChangedButton == PanningMouseButton)
    {
        this.Cursor = Cursors.ScrollAll;
        _lastMousePos = e.GetPosition(null);
        this.CaptureMouse();
    }
}

private void This_MouseUp(object sender, MouseButtonEventArgs e)
{
    if (e.ChangedButton == PanningMouseButton)
    {
        this.ReleaseMouseCapture();
        this.Cursor = Cursors.Arrow;
    }
}

private void This_MouseMove(object sender, MouseEventArgs e)
{
    if (this.IsMouseCaptured)
    {
        Point newMousePos = e.GetPosition(null);
        Vector shift = newMousePos - _lastMousePos;
        _translateT.X += shift.X;
        _translateT.Y += shift.Y;
        _lastMousePos = newMousePos;
    }
}

谢谢DeepZoom似乎是一个不错的解决方案,但有点过载。添加了另一个建议大纲,该大纲在大图像性能方面更差,但更简单。谢谢H.B。!它对我很管用,而且性能也没那么差;)美好的除非您仍在寻找更好的解决方案,否则您可以通过单击我答案左侧的复选标记来接受这一点。能否请您更具体地说明性能有多好?图像有多大?谢谢