开发者

Fixed deep zoom

Is there any way to perform a fixed zoom on a multiscaleimage in deep zoom? i.e. click once to zoom about point X,Y to 2x, click again to restore to the original position and zoom level?

I have written the code to zoom in and out but calling zoomaboutlogicalpoint midway through the zoom process results in zooming out too far (I guess due to the 1/2 factor in the mouse up event - can I obtain the zoom level?). Also I'd like the zoomed out image to be central (I guess i change the point to zoom to that midway in the image but this doesnt seem to work, perhaps I need to factor in the ViewPort position?)

e.g.

private void msi_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {

Point p = e.GetPosition(msi); Zoom(2, p); }

private void msi_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {

Point p = e.GetPosition(msi); Zoom(1/2, p); }

    public void Zoom(double zoom, Point pointToZoom)
    {
        bool zoom开发者_Go百科ingIn = zoom > 1;
        bool zoomingOut = zoom < 1;
        double minViewportWidth = 0.05;
        double maxViewportWidth = 1;

        if (msi.ViewportWidth < minViewportWidth && zoomingIn)
        {
            return;
        }

        if (msi.ViewportWidth > maxViewportWidth && zoomingOut)
        {
            return;
        }

        Point logicalPoint = this.msi.ElementToLogicalPoint(pointToZoom);
        this.msi.ZoomAboutLogicalPoint(zoom, logicalPoint.X, logicalPoint.Y);

    } 

Thanks.


Resetting the transform origin before zooming out seems to have done the trick:

msi.RenderTransformOrigin = new Point(msi.Height / 2, msi.Width / 2);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜