Android中调用相册里面的图片并返回:

时间:2023-01-12 08:46:12

Android中调用相册里面的图片并返回:

Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
   intent.addCategory(Intent.CATEGORY_OPENABLE);
   intent.setType("image/*");
   intent.putExtra("crop", "true");
   intent.putExtra("aspectX", 1);
   intent.putExtra("aspectY", 1);
   intent.putExtra("outputX", 80);
   intent.putExtra("outputY", 80);
   intent.putExtra("return-data", true);

   startActivityForResult(intent, 0);



在原来的Activity中如下获取选到的图片:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 System.out.println(resultCode);
 Bitmap cameraBitmap = (Bitmap) data.getExtras().get("data");
 super.onActivityResult(requestCode, resultCode, data);

}

本文出自 “享受编程” 博客,请务必保留此出处http://kure6.blog.51cto.com/2398286/1201949