有些情况下,我们不需要将图片读入内存,只想获取图片的宽高,这要怎么做呢?看下面的代码:
private
Bitmap decodeThumbBitmapForFile(String path,
int
viewWidth,
int
viewHeight){
BitmapFactory.Options options =
new
BitmapFactory.Options();
//设置为true,表示解析Bitmap对象,该对象不占内存
options.inJustDecodeBounds =
true
;
BitmapFactory.decodeFile(path, options);
//设置缩放比例
options.inSampleSize = computeScale(options, viewWidth, viewHeight);
//设置为false,解析Bitmap对象加入到内存中
options.inJustDecodeBounds =
false
;
return
BitmapFactory.decodeFile(path, options);
}