Uri uri = data.getData();/* * 此时会抛出异常* Uri uri = data.getData();InputStream isl = getContentResolver().openInputStream(uri);Bitmap b = BitmapFactory.decodeStream(isl);*/try {InputStream is = getContentResolver().openInputStream(uri);BitmapFactory.Options opts = new Options();opts.inJustDecodeBounds = true;BitmapFactory.decodeStream(is, null, opts);//图片宽高int bitmapHeight = opts.outHeight;int bitmapWidth = opts.outWidth;int windowHeight = wm.getDefaultDisplay().getHeight();int windowWidth = wm.getDefaultDisplay().getWidth();//需要缩放if(bitmapHeight>windowHeight || bitmapWidth>windowWidth){int scaleX = bitmapWidth/windowWidth;int scaleY = bitmapHeight/windowHeight;if(scaleX>scaleY){//按照水平方向缩放opts.inSampleSize = scaleX;} else {//按照竖直方向缩放opts.inSampleSize = scaleY;}} else {//不用缩放opts.inSampleSize = 1;}//真正的解析图片opts.inJustDecodeBounds = false;//需要注意的事情 is先前已经用过  后面还要继续用 故需要重新获取is = getContentResolver().openInputStream(uri);Bitmap bitmap = BitmapFactory.decodeStream(is, null, opts);ib_main_logo.setImageBitmap(bitmap);} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}

更多相关文章

  1. android 按钮的点击缩放
  2. Android(安卓)图片缩放实例详解
  3. android 按比例缩放图片(适屏)
  4. android 方式实现imageview圆角
  5. ViewPager
  6. Android(安卓)popupwindow的基本使用
  7. 最受欢迎的文章汇总
  8. Android(安卓)调用相册 拍照 实现系统控件缩放 切割图片
  9. Android图片缩放总结及比较

随机推荐

  1. Android音视频处理之MediaMuxer
  2. android 应用程序使用统计
  3. Android(安卓)OTA 系统升级 笔记
  4. How to display a custom dialog in your
  5. Android创建快捷方式图标
  6. 手动修改Android数据库数据
  7. android发送QQ邮件(带附件)
  8. Android(安卓)检测用户一段时间无操作
  9. Android复习(十一)
  10. Android批量插入数据