簡體   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