C# 获取Picturebox中缩放图像的确切大小
我正在使用WinForms。在我的表格中,我有一个C# 获取Picturebox中缩放图像的确切大小,c#,.net,image,winforms,picturebox,C#,.net,Image,Winforms,Picturebox,我正在使用WinForms。在我的表格中,我有一个图片盒。它的sizemode设置为缩放。如果我将图像加载到picturebox中,图像将根据picturebox尺寸进行缩放 我想知道如何在picturebox中获得缩放图像的大小 这些是我尝试过的一些事情,但这并没有给我想要的结果 private void Debug_Write_Click(object sender, EventArgs e) { //var pictureWidth = pictureBox
图片盒
。它的sizemode设置为缩放
。如果我将图像加载到picturebox
中,图像将根据picturebox
尺寸进行缩放
我想知道如何在picturebox
中获得缩放图像的大小
这些是我尝试过的一些事情,但这并没有给我想要的结果
private void Debug_Write_Click(object sender, EventArgs e)
{
//var pictureWidth = pictureBox1.ClientSize.Width; //This gives the size of the picturebox
//var picturewidth1 = pictureBox1.Image.Width; This gives the actual size of the image
//var pictureHight = pictureBox1.ClientSize.Height; //This gives the size of the picturebox
//var pictureHight1 = pictureBox1.ClientSize.Height; This gives the actual size of the image
Debug.WriteLine("Width: " + pictureWidth.ToString() + " Height: " + pictureHight.ToString());
}
例如:
图像的实际大小
Picturebox
大小模式设置为Zoom
,因此它根据我的Picturebox
大小缩放图像:
如何计算出这张图像的缩放长度和宽度?你应该计算一下
Image img = //...;
PictureBox pb = //...;
var wfactor = (double)img.Width / pb.ClientSize.Width;
var hfactor = (double)img.Height / pb.ClientSize.Height;
var resizeFactor = Math.Max(wfactor, hfactor);
var imageSize = new Size((int)(img.Width / resizeFactor), (int)(img.Height / resizeFactor));
您所说的picturebox内缩放图像的大小是什么意思?图像的实际大小?例如,假设我的
picturebox
长度为1000,宽度为500,我的图像长度为2000,宽度为1000。当图像加载到picturebox
中时,它会相应地重新调整大小。我想知道如何找到已重新调整大小以适合picturebox
的图像的长度和宽度@DotTorZoom保留图像的纵横比,因此您必须对使用的最大尺寸、宽度或高度进行一些计算,然后相应地计算其他数字。pb.ClientSize.width代码>,如果控件使用边框。:-)@LarsTech Nice,添加到回答中。Image img=pictureBox1.Image;PictureBox pb=新PictureBox();这两行是否正确?Image img=pictureBox1.Image;PictureBox pb=pictureBox1代码>@Taji01谢谢你的帮助!我对这一切还是新手:)