相册选择照片

 1         switch (requestCode) {
 2         case REQUEST_FROM_ALBUM:
 3             Uri uri = data.getData();
 4             String path = Utils.getImageAbsolutePath(FeedBackActivity.this, uri);
 5             Logger.d(Const.Tag_Log, "path:" + path);
 6             if (path != null) {
 7                 File file = new File(path);
 8                 if (file != null) {
 9                     Logger.d(Const.Tag_Log, "fileLen:" + file.length());
10                 }
11             }
12 
13             Bitmap photo = null;
14             try {
15                 photo = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
16             } catch (FileNotFoundException e) {
17                 e.printStackTrace();
18             } catch (IOException e) {
19                 e.printStackTrace();
20             }
21             if (photo != null) {
22                 // TODO 缩放
23                 // //为防止原始图片过大导致内存溢出,这里先缩小原图显示,然后释放原始Bitmap占用的内存
24                 // Bitmap smallBitmap = ImageTools.zoomBitmap(photo,
25                 // photo.getWidth() / SCALE, photo.getHeight() / SCALE);
26                 // //释放原始图片占用的内存,防止out of memory异常发生
27                 // photo.recycle();
28 
29                 mIv.setImageBitmap(photo);
30             }
31             break;
32 
33         default:
34             break;
35         }

 

posted @ 2017-04-07 09:23  鲸歌  阅读(158)  评论(0编辑  收藏  举报