Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调整PictureBox的大小_C#_Image_Resize_Picturebox - Fatal编程技术网

C# 调整PictureBox的大小

C# 调整PictureBox的大小,c#,image,resize,picturebox,C#,Image,Resize,Picturebox,我想在我的Picturebox中显示调整大小的图片。 原图为: 还有我表格中的图片: 我的图片盒尺寸是500x500px。 我用于调整大小的方法: public static Image ResizePicByWidth(Image sourceImage, double newWidth) { double sizeFactor = newWidth / sourceImage.Width; double newHeigth = sizeFac

我想在我的Picturebox中显示调整大小的图片。 原图为: 还有我表格中的图片:

我的图片盒尺寸是500x500px。 我用于调整大小的方法:

    public static Image ResizePicByWidth(Image sourceImage, double newWidth)
    {
        double sizeFactor = newWidth / sourceImage.Width;
        double newHeigth = sizeFactor * sourceImage.Height;
        Bitmap newImage = new Bitmap((int)newWidth, (int)newHeigth);
        using (Graphics g = Graphics.FromImage(newImage))
        {
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.DrawImage(sourceImage, new Rectangle(0, 0, (int)newWidth, (int)newHeigth));
        }
        return newImage;
    }
我使用原始图片和picturebox中的宽度调用该方法。 但是如何正确调整图片的大小?
我希望我的表单显示整个图片。

PictureBox具有SizeMode属性。如果将此设置为“缩放”,它将自动调整其中图像的大小以适合其内部。

PictureBox具有SizeMode属性。如果将此设置为“缩放”,它将自动调整图像的大小,使其适合图像。

只需将图片的宽度和高度设置为所需的值。您已设置了新的宽度,但实际上也设置了新的宽度,以使picturebox适应新的高度。或者将sizemode设置为缩放。在这种情况下,你根本不需要做任何调整!对不起,你的英语不好。。但是Sizemode是解决办法你的英语不好。嗯,我肯定你不是这个意思;-)顺便说一句,这里强烈反对用“ur”代替“your”或“you're”,甚至用“i”代替“i”。因此,它不是一个论坛,而是一个档案,每一个打字错误都有可能被保存多年。只需将图片的宽度和高度设置为您想要的值。您已经设置了一个新的宽度,但实际上也是新的,以使图片框适应新的高度。或者将sizemode设置为缩放。在这种情况下,你根本不需要做任何调整!对不起,你的英语不好。。但是Sizemode是解决办法你的英语不好。嗯,我肯定你不是这个意思;-)顺便说一句,这里强烈反对用“ur”代替“your”或“you're”,甚至用“i”代替“i”。因此,这不是一个论坛,而是一个档案,每一个打字错误都有可能被保存多年……这确实有效。是我的错。我将BackgroundImageLayout设置为缩放而不是缩放SizeMode。谢谢你的工作。是我的错。我将BackgroundImageLayout设置为缩放而不是缩放SizeMode。谢谢