0

我想要的是将任何尺寸大于 480k 像素的图片缩小到 480k 像素或更小;

-- maxSize = 480k
-- picture1.Size = 1600*300 = 480k = maxSize => that's OK.
-- picture2.Size = 2600*200 = 520k => problem (should be reduced to maxSize or less).

picture2.Size / maxSize = 1.083

picture2.Size/1.083 = 480148 (~= maxSize) => that's OK.

假设 1.083 是图片调整大小的比率: ratio = 1.083;

如何应用此比例来保持图片纵横比?

4

2 回答 2

1

你只想解决系统:

newWidth * newHeight = maxSize;
newWidth / newHeight = picture2.Width / picture2.Height

解决方案是:

double newWidth = Math.Sqrt(picture2.Width * maxSize / picture2.Height);
double newHeight = Math.Sqrt(picture2.Height * maxSize / picture2.Width);

这样,picture2将保留纵横比,并且尺寸不会超过maxSize

于 2013-11-10T17:57:38.530 回答
0

(2600-x)/(200-y) = 2600/200 和 x*y = 1.083

现在图片可以重新缩放到小于 maxSize 的大小,并且纵横比也保持不变。

于 2013-11-10T17:55:34.990 回答