在C#中的画布中缩放对象 [英] zooming object in canvas in C#

查看:406
本文介绍了在C#中的画布中缩放对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Point ptMousePos = new Point();
            ptMousePos = e.GetPosition(this);

            
            double height = this.ActualHeight;
            double width = this.ActualWidth;
            double zoom=e.Delta;
            
           
            zoom = zoom/1200;

            double dTempZoom = m_dZoomDelta + zoom;

            if (dTempZoom < 0.01)
                  return;

            m_dZoomDelta += zoom;
            
            if (m_dZoomDelta < 0)
                m_dZoomDelta = Math.Abs(m_dZoomDelta / zoom);

        
            this.Width = (int) Math.Abs(1000 * m_dZoomDelta);
            this.Height = (int) Math.Abs(1000 * m_dZoomDelta);

            if (this.Width < 1000)
            {
                this.Width = 1000;
                this.Height = 1000;
            }
  
           
           

            ScaleTransform sc = new ScaleTransform(m_dZoomDelta, m_dZoomDelta, ptMousePos.X, ptMousePos.Y);
            this.LayoutTransform = sc;
            this.UpdateLayout();
        }


上面的代码我尝试过对我有用,但是未设置滚动位置,以便可以从中心缩放对象
这样任何人都可以帮助我........


Above code i have tried it work for me but the position of scroll is not set such that the object can be zoom from center
so anybody can help me ........

推荐答案

如果您要放大特定的图像,则需要应用TranslateTransform和ScaleTransform点.
You need to apply a TranslateTransform as well as a ScaleTransform if you want to zoom in on a particular point.


这篇关于在C#中的画布中缩放对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆