2013-07-04 212 views
1

我在调整图像大小时遇到​​问题。调整图像大小

首先在开始时我有一个图像,例如在1920x1080。用户输入是调整当前图像大小的百分比,例如,当输入为25%时,图像的最终分辨率为960x540。

说明:

1920x1080 = 2 073 600 
25% from 2 073 600 = 518 400 
960x540 = 518 400 

我已经有调整图像大小的功能,但我不知道如何CALCULATEWIDTH高度为调整后的图像。

我的例子是960x540。 (如果它可以帮助你,图像具有比3:2,4:3,16:9 ....)

任何帮助吗?

回答

4

你必须给你的以下信息:

width = 1920 
height = 1080 
area = 2073600 
ratio = width/height =~ 1.77778 

现在,假设例如你希望在区域缩小到现在的规模的25%来计算新的宽度和高度。那好吧,我们知道以下几点:

area = 0.25 * 2073600 = 518400 
height = h (Variable, because it is unknown at the moment) 
width = w (Variable, because it is unknown at the moment) 

ratio = 1.77778 (Ratio should stay the same or image becomes warped/stretched) 

所以,你必须

w/h = 1.77778 (Your unknown new width divided by unknown height equals ratio) 
w * h = 518400 (Your unknown width times unknown height equals area) 

现在你可以解决它相对容易数学。它只是两个有两个变量的方程。

w = 1.77778 * h (from first equation) 
(1.77778 * h) * h) = 518400 (by plugging above into second equation) 
h =~ 540 
w =~ 960 

这有道理吗?

+0

我不能甚至说多少我感谢你! –

+0

没问题,很高兴我能帮上忙。 – Kon