我想缩放图像,但我不希望图像看起来歪斜。
图片必须为 115x115(长 x 宽)。
图片不能超过 115 像素高(长度),但如果需要,宽度可以小于 115 但不能超过。
这很棘手吗?
最佳答案
您需要保持纵横比:
float scale = 0.0;
if (newWidth > maxWidth || newHeight > maxHeight)
{
if (maxWidth/newWidth < maxHeight/newHeight)
{
scale = maxWidth/newWidth;
}
else
{
scale = maxHeight/newHeight;
}
newWidth = newWidth*scale;
newHeight = newHeight*scale;
}
在代码中,最初的newWidth/newHeight是图片的宽/高。
关于c# - 缩放图像,但保持其比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1979958/