码迷,mamicode.com
首页 > 其他好文 > 详细

提取SD卡中的图片

时间:2015-05-20 23:48:38      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

读取SD卡的权限

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

系统跳转
startActivityForResult(new Intent(Intent.ACTION_PICK).setType("image/*"),PICK_CODE);

回来后取得图片
 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==PICK_CODE){
if(data!=null){
// 获取图片地址
//
Cursor cursor=getContentResolver().query(data.getData(), null, null, null, null);
cursor.moveToFirst();
currentPhotoStr=cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA));
cursor.close();
// 压缩图片
resizePhoto();
imageView.setImageBitmap(photoImage);
}
}
}


压缩图片

private void resizePhoto() {
BitmapFactory.Options options=new BitmapFactory.Options();
options.inJustDecodeBounds=true;
BitmapFactory.decodeFile(currentPhotoStr,options);
double ratio=Math.max(options.outWidth*1.0d/1024f,options.outHeight*1.0d/1024f);
options.inSampleSize=(int)Math.ceil(ratio);
options.inJustDecodeBounds=false;
photoImage= BitmapFactory.decodeFile(currentPhotoStr, options);
}

提取SD卡中的图片

标签:

原文地址:http://www.cnblogs.com/jetereting/p/4518408.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!