[英]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.