1. android 调用系统相机的方式:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent, 1);
2. 在onActivityResult中处理图片
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data == null) return; if (resultCode == Activity.RESULT_OK) { if (requestCode == 1) { Bundle bundle = data.getExtras(); if (bundle == null) return; Bitmap bitmap = (Bitmap) bundle.get("data");
if (biemap != null) imageView.setImageBitmap(bitmap); }
}
}
3. Android调用系统相册的方式:
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT); galleryIntent.addCategory(Intent.CATEGORY_OPENABLE); galleryIntent.setType("image/*"); startActivityForResult(galleryIntent, 2);
4. 在onActivityResult中处理图片
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data == null) return; if (resultCode == Activity.RESULT_OK) { if (requestCode == 2) { Uri mUri = data.getData(); if (mUri == null) return; try { Bitmap bm = BitmapFactory.decodeStream(getContentResolver().openInputStream(mUrl)); if (bm != null) {imageView.setImageBitmap(bm);}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}