如何获得缩放以适合图片框的图像的显示图像尺寸 [英] How to get displayed Image dimensions of an Image scaled to fit a PictureBox

查看:65
本文介绍了如何获得缩放以适合图片框的图像的显示图像尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能获得已重新调整大小以适合图片框的图像的显示图像尺寸.

I am wondering if it is possible to get the displayed image dimensions of an image that has been re-sized to fit a PictureBox.

PictureBox 的 SizeMode 属性设置为 Zoom.所以原始图像的纵横比被保留.但是,我需要获取显示的图像大小,这不是通过 API 公开可用的.

The PictureBox's SizeMode property is set to Zoom. So the aspect ration of the original Image is preserved. I need to get the displayed Image size however, which is not publicly available through the API.

我已经阅读了一些包含反思的答案,但我宁愿不这样做.

I have read some answers that included reflection, but I would rather not do this.

推荐答案

最简单的方法就是自己获取纵横比,毕竟这是简单的数学运算.

Easiest way is to just grab the aspect ratio yourself it's simple math after all.

首先确定图像是垂直的还是水平的,然后简单地获取图片框的高度或宽度(分别),并根据该值确定原始图像纵横比的宽度或高度(分别).

First determine the if the image is vertical or horizontal then simply grab the picturebox height or width (respectively) and determine the width or height (respectively) of the original image's aspect ratio given that value.

OriginalImg.Height/OriginalImage.Width x PictureBox.Width = PictureBox.Height

OriginalImg.Height / OriginalImage.Width x PictureBox.Width = PictureBox.Height

这篇关于如何获得缩放以适合图片框的图像的显示图像尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆