内存加载图片压缩 BitmapFactory.Options

 
  
/**
*imgUrl 要压缩的力图片地址
**/
public Bitmap CompressedImage(String imgUrl) {
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;  //为true时只加载图片的宽高,不加载实际内容
options.inPreferredConfig =Bitmap.Config.RGB_565;
 BitmapFactory.decodeFile(imgUrl, options);
//int W = options.outWidth ;
//int H = options.outHeight ;
options.inSampleSize =  5; //inSampleSize=5,载入的压缩图是原图的1/4。因为inSampleSize只能是2的整数次幂,如果不是,就向下取最大的2的整数次幂
options.inJustDecodeBounds = false; 
return BitmapFactory.decodeFile(imgUrl, options); 
}

你可能感兴趣的:(android)