//Uri.parse("file://"+result.getImage().getCompressPath()))        String path=uri.getPath();        Log.e("图片路径",path+"");        SpannableString spannableString=new SpannableString(path);        //方法一:通过uri把图片转化为bitmap的方法        Bitmap bitmap= BitmapFactory.decodeFile(path);       int height= bitmap.getHeight();        int width= bitmap.getWidth();        Log.e("通过bitmap获取到的图片大小","width:"+width+"height"+height);        //方法二:使用Options类来获取        BitmapFactory.Options options = new BitmapFactory.Options();        options.inJustDecodeBounds = true;//这个参数设置为true才有效,        Bitmap bmp = BitmapFactory.decodeFile(path, options);//这里的bitmap是个空        if(bmp==null){            Log.e("通过options获取到的bitmap为空","===");        }        int outHeight=options.outHeight;        int outWidth= options.outWidth;        Log.e("通过Options获取到的图片大小","width:"+outWidth+"height"+outHeight);

关于两种方法:第一种直接把bitmap加载到内存中,通过对bitmap的测量,得出宽高,由于这个方法直接把图片引入内存,如果图片过大,将会引发OOM;

第二种方法:bitmap.options类为bitmap的裁剪类,通过他可以实现bitmap的裁剪;如果不设置裁剪后的宽高和裁剪比例,返回的bitmap对象将为空,但是这个对象存储了原bitmap的宽高信息。


打log输出信息如下:

缩放:

  Bitmap bitmap=null;        BitmapFactory.Options options=new BitmapFactory.Options();        options.inSampleSize=2;        options.inJustDecodeBounds = false;        if(path.equals("a1")){            bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.a1,options);

inSampleSize表示缩放比例

更多相关文章

  1. Android(安卓)View的小结
  2. weex android 选择文件 拍照 获得uri 并转为文件真实路径 转base
  3. chromium判断是否支持硬件加速的方法
  4. Android(安卓)学习笔记(二) 各种技巧小知识
  5. Android:自定义控件和使用方法
  6. Android中定义接口的方法
  7. BitMap、Drawable、inputStream及byte[] 互转
  8. AsyncTaskLoader使用方法
  9. Android中常用方法的归纳集合总结(二)

随机推荐

  1. The RK3066/RK30SDK Android(安卓)4.2 au
  2. Android(安卓)约束布局(ConstraintLayout)
  3. android 周报 - 2019/10/6-Issue #382
  4. android 图片处理工具类,Bitmap转换String
  5. android 项目中设置背景图片
  6. 4.0 以上插耳机让音乐在耳机播放,屏蔽掉
  7. 一段漂亮的Fragment hide,show相关的代码
  8. RxJava操作符在android中的使用场景详解(
  9. Android(安卓)Toast 部分手机无法显示问
  10. Android(安卓)RemoteViews原理