繁体   English   中英

如何在不影响Java中的图像实际纵横比的情况下,为图像计算新的高度和宽度以适合预定义的高度和宽度?

[英]How to calculate new height and width for an image to fit with in predefined height and width, without affecting the image real aspect ratio in java?

我想缩放图像以适合某些预定义的大小,而不影响实际图像的宽高比。

我们在Java中是否有任何预定义的算法?

更新:

调整大小。 输出是相同的图像,但尺寸较小。 外框只是一个标记。

在此处输入图片说明

您在宽度或高度上都会有差距...问题正在弄清楚哪一个。

double widthRatio = realWidth / definedWidth;
double heightRatio = realHeight / definedHeight;

if(heightRatio > widthRatio) {
    // scale image to match the height, and let the width have the gaps

} else {
    // scale image to match the width, and let the height have the gaps

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM