0
在教程的一個谷歌提出了以下縮放位算法,使位圖適合一個給定的窗口:無法理解這樣的大規模位代碼
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float)height/(float)reqHeight);
} else {
inSampleSize = Math.round((float)width/(float)reqWidth);
}
}
return inSampleSize;
}
(http://developer.android.com/training/displaying-bitmaps/load-bitmap.html)
我不明白if(width > height)
部分
假設一個位圖的高度爲5,寬度爲2.那麼假設一個窗口的高度爲1,寬度爲1.它看起來像位圖不適合窗口。