bitmap缩放的原理代码


BitmapFactory.Options options =newBitmapFactory.Options();

options.inJustDecodeBounds=true;

//获取这个图片的宽和高,注意此处的bitmap为null

bitmap= BitmapFactory.decodeFile(mPics.get(position), options);

options.inJustDecodeBounds=false;//设为false

//计算缩放比

inth = options.outHeight;

intw = options.outWidth;

intbeWidth = w /150;

intbeHeight = h /100;

intbe =1;

if(beWidth < beHeight) {

be = beWidth;

}else{

be = beHeight;

}

if(be <=0) {

be =1;

}

options.inSampleSize= be;

//重新读入图片,读取缩放后的bitmap,注意这次要把options.inJustDecodeBounds设为false

bitmap= BitmapFactory.decodeFile(mPics.get(position), options);

//利用ThumbnailUtils来创建缩略图,这里要指定要缩放哪个Bitmap对象

//                        bitmap = ThumbnailUtils.extractThumbnail(bitmap, 150, 100,

//                                                                ThumbnailUtils.OPTIONS_RECYCLE_INPUT);

viewHolder.imageView.setImageBitmap(bitmap);

// bitmap.recycle();

你可能感兴趣的:(bitmap缩放的原理代码)