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

问题描述 投票:10回答:1

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

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

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

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倍)图像的截图。注意图像上边框和表单上边框之间的边距。

c# winforms image picturebox zooming
1个回答
3
投票

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

How to zoom in&out an image in c#

© www.soinside.com 2019 - 2024. All rights reserved.