变焦/伸展当前鼠标的位置一个PictureBox? [英] Zooming / stretching a picturebox on current mouse position?

查看:174
本文介绍了变焦/伸展当前鼠标的位置一个PictureBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问:我如何能实现在一个PictureBox当前鼠标位置缩放,像在谷歌地图缩放

我设计一个简单的GIS /地图引擎作为我的论文工作。应用程序设计,该地图被加载到sligtly改性的tabcontrol的标签这样的方式。

I am designing a simple GIS / map engine as my thesis work. The application is designed in such a way that the maps are being loaded into tabs of a sligtly modified tabcontrol.

地图是标准的JPEG或PNG格式的数字图像,其中大部分具有非常高的分辨率(2000x2000px及以上)。

Maps are standard JPEG or PNG format digital images and most of them have very high resolutions (2000x2000px and up).

他们被加载在那些加入的TabPages的子控件pictureboxes。我实现了一个简单的缩放方法作为按钮的单击事件,只有放大到图像/图片框的中心。

They are loaded in pictureboxes that are added as subcontrols of tabpages. I've implemented a simple zooming method as a button click event that only zooms to the center of the image/picturebox.

我想什么做的是落实缩放。在这样的画面被放大在当前鼠标位置的图片框内部的鼠标滚轮事件

What i would like to do is implement the zooming on a mousewheel event in that way that the picture is being zoomed on the current mouse position inside of the picturebox.

有关当前放大的代码看起来是这样的:

The code for zooming in currently looks like this:

            timesZoomed += 1;
            zoomRatio += 0.1f;
            pbxMapa.Width = pbxMapa.Width * zoomRatio;
            pbxMapa.Height = pbxMapa.Height * zoomRatio;
            pbxMapa.Location = new Point((this.Width / 2) - (pbxMapa.Width / 2), this.Height / 2) - (pbxMapa.Height / 2));




  • 默认zoomRatio值为1,并且它是被增加高达0.6f。

  • 参数timesZoomed默认值是0,它上升到6。

  • pbxMapa与PictureBox的地图加载图像。该图片的ImageSizeMode道具设定为缩放,但该图片的大小设置为加载的地图图像的全尺寸。

  • 另外,我是用这个简单的缩放代码实验。计算是有点效果,但它仍然有相当的缩放/一个更大的比例乘以时偏移:

    Also, i was experimenting with this simple zooming code. The calculation is somewhat effective, but still it has quite an offset when zooming/multiplying with a bigger ratio:

                    pbxMapa.Location = new Point(pbxMapa.Location.X + (int)((pbxMapa.Location.X * zoomRatio - mouseXPbx) / 8), pbxMapa.Location.Y + (int)((pbxMapa.Location.Y * zoomRatio - mouseYPbx) / 8));
    




    • mouseXPbx和mouseYPbx变量代表内部当前鼠标的位置在pbxMapa的。我8最大限度地减少在定位偏移分。

    • 任何帮助和建议表示赞赏,感谢在前进。

      Any help and suggestions is appreciated, thanks in advance.

      推荐答案

      下面的代码缩放和拉伸图片框上当前鼠标位置

      the code below zoomed and stretched the pictureBox on the current mouse position

      pictureBox1.Width = (int)(pictureBox1.Width * zoomratio );
      pictureBox1.Height = (int)(pictureBox1.Height * zoomratio );                
      pictureBox1.Top = (int)(e.Y - zoomratio * (e.Y - pictureBox1.Top));
      pictureBox1.Left = (int)(e.X - zoomratio * (e.X - pictureBox1.Left));
      

      这篇关于变焦/伸展当前鼠标的位置一个PictureBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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