![](/img/trans.png)
[英]Getting Height and Width of Image in Java without an ImageObserver
[英]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.