2011-04-09 102 views
2

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

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

回答

1

也许像DeepZoom这样的工作。


您还可以使用平移功能创建简单的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; 
    } 
} 
+0

谢谢。 DeepZoom似乎是一个很好的解决方案,但一点点超载。 – timmes 2011-04-09 17:35:49

+0

增加了另一个建议大纲,对于巨大的图像而言性能更差,但更简单。 – 2011-04-09 18:10:46

+0

谢谢H.B.!它适用于我,表现并不那么差:) – timmes 2011-04-11 07:13:22