1:启动相机:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//实例化Intent对象,使用MediaStore的ACTION_IMAGE_CAPTURE常量调用系统相机 String name = "image" ; imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), name)); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); startActivityForResult(intent, requestCode);
2:在onResultActivity
Bitmap bitmap= null; try { bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri)); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
3:问题:
调用相机的时候,点击确定,没有任何反应,后面发现,是URI的路径不对,导致图片无法保存;
系统相机可以通过onresult的 intent data获取bitmap,但是得到的数据太小太模糊,这是因为系统获取到的图片太大,如果通过intent返回,可能会导致OOM,所以系统返回的是压缩后的图片。所以需要我们动手将图片保存到本地,在onResultActivity里面通过本地URI获取。