且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在不延伸/扭曲C#的情况下调整图像大小?

更新时间:2023-09-16 23:35:58

调整时必须保持纵横比相同大小,你不能只使用任意值的宽度和高度。



我在 http://blogs.techrepublic上找到了这个.com / howdoi /?p = 124 [ ^ ]

You must keep the aspect ratio the same when adjusting the size, you cannot just use arbitrary values for the width and height.

I found this at http://blogs.techrepublic.com/howdoi/?p=124[^]
The key to keeping the correct aspect ratio while resizing an image is the algorithm used to calculate the ratio, viz.

NewHeight = GivenWidth * (OriginalHeight / OriginalWidth)

or

NewWidth = GivenHeight * (OriginalWidth / OriginalHeight)

This calculation assumes that the "Given..." is the dimension the image should be resized to. Once we know this, we can multiply it by the original image’s aspect, and that will give us the other side's value we need. So, assuming the original image has a width of 1000 and a height of 1600 and we want it to be resized to a width of 500:

First find the aspect: (1600 / 1000) = aspect of 1.6
Now multiply the aspect by the desired new width: 1.6 * 500
The result of that multiplication is 800, which is what our height should be

In other words:
800 = 500 * (1600 / 1000)

So the resulting image would have a height of 800 and a width of 500.

>