2012-05-19 30 views
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.它看起来像位图不适合窗口。

回答

1

这可确保大小比尊重