C# 获取指定固定范围内的比例固定的实际图片大小
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); } }
桂棹兮兰桨,击空明兮溯流光。