Rectangle? getImageRegion(PictureBox pic) { if (pic.Image == null) return null; var picHeight = pic.Width * pic.Image.Height / pic.Image.Width; if (picHeight > pic.Height) { var imageHeight = pic.Height; var imageWidth = imageHeight * pic.Image.Width / pic.Image.Height; return new Rectangle((pic.Width - imageWidth) / 2, (pic.Height - imageHeight) / 2, imageWidth, imageHeight); } else { var imageWidth = pic.Width; var imageHeight = imageWidth * pic.Image.Height / pic.Image.Width; return new Rectangle((pic.Width - imageWidth) / 2, (pic.Height - imageHeight) / 2, imageWidth, imageHeight); } }
标签:C#,Image,pic,Height,Width,imageHeight,固定,imageWidth,图片大小 From: https://www.cnblogs.com/nanfei/p/16982918.html