• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
jetereting
博客园    首页    新随笔    联系   管理    订阅  订阅

提取SD卡中的图片

读取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);
}
posted @ 2015-05-20 22:39  jetereting  阅读(578)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3