小编use*_*389的帖子

android - calculateInSampleSize,为什么当宽度>高度时Math.round处理高度(高度/ reqHeight)?

我正在'developer.android.com'上缩小我的位图文件,我发现了一件我不理解的事情.所以我感谢你给我一点帮助.

这是developer.android.com 的一个片段

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;
}
Run Code Online (Sandbox Code Playgroud)

在if语句中,当"if(width> height)"为什么会计算"(float)height /(float)reqHeight"?

例如,width = 600,height = 800,reqWidth = 100,reqHeight = 100. …

android bitmapfactory

10
推荐指数
1
解决办法
5191
查看次数

标签 统计

android ×1

bitmapfactory ×1