刚进入到位图采用的学习当中,遇到了一个逻辑问题,实在绕不过弯来。。。
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;
}
关于上面的代码
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float) height / (float) reqHeight);
} else {
inSampleSize = Math.round((float) width / (float) reqWidth);
}
}
是什么意思呀?为什么按照小的长度去取比例呢?我怎么感觉会出现逻辑漏洞呢?
比如原始图片是 width=400;height=200; reqwidth=400;reqheight=100;又或者reqwidth=200;reqheight=200;
那采集的图片不就成了要么缩小一半,要么不动吗?还有原始图片是正方形咋取?