C#:使用滚动条缩放图片框图像的简单而实用的方法

是否有一种简单而实用的方法来缩放图片框中的图像,包括滚动条?

目前,我在面板中使用了一个自动滚动激活的图片框。 要进行缩放,我会放大图片框并使用面板上的滚动条移动它。 问题是,它表现得很奇怪。 例如:如果放大到远,则上下左边的边框和图像之间的边距越来越大。

这是缩放方法。 我是从这里得到的。

private void ZoomInOut(bool zoom) { //Zoom ratio by which the images will be zoomed by default int zoomRatio = 10; //Set the zoomed width and height int widthZoom = pictureBox_viewer.Width * zoomRatio / 100; int heightZoom = pictureBox_viewer.Height * zoomRatio / 100; //zoom = true --> zoom in //zoom = false --> zoom out if (!zoom) { widthZoom *= -1; heightZoom *= -1; } //Add the width and height to the picture box dimensions pictureBox_viewer.Width += widthZoom; pictureBox_viewer.Height += heightZoom; } 

任何帮助表示赞赏。

提前致谢。

马尔科

编辑:两张未曝光和缩放(16倍)图像的截图。 注意图像上边框和表单上边框之间的边距。 UnzoomedImageZoomedImage

我认为最好缩放(重新缩放)图像而不是图片框。 看一下这篇文章 – http://www.codeproject.com/Articles/21097/PictureBox-Zoom

如何在c#中放大和缩小图像