根據實際要求尺寸顯示原圖

public static Bitmap decodeSampledBitmapFromResource( Resources res,int resId,int reqWidth,int reqHeight){ 

//先通過inJustDecodeBounds=true獲取圖片尺寸

BitmapFactory.Option options=new BitmapFactory.Options();

options.inJustDecodeBounds=true;

BitmapFactory.decodeResource(res,resId,options);

//根據圖片分辨率以及實際需要的展示尺寸,計算壓縮率

options.inSampleSize=calculateInSampleSize(options,reqWidth,reqHeight);

//設置壓縮率,並解碼

options.inJustDecodeBounds=false;

return BitmapFactory.decodeResource(res,resId,options);

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章