【问题标题】:Can not understand this scale bitmap code看不懂这个比例位图代码
【发布时间】:2012-08-16 01:41:34
【问题描述】:

在其中一个教程中,Google 提出了以下缩放位图算法以使位图适合给定窗口:

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。看起来位图不适合窗口。

【问题讨论】:

    标签: android bitmap


    【解决方案1】:

    确保尺寸比例得到尊重

    【讨论】:

      猜你喜欢
      • 2017-10-13
      • 2023-03-28
      • 2017-05-16
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      • 2013-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多