What data is returned when using ACTION_IMAGE_CAPTURE?

耗尽温柔 提交于 2019-12-06 00:01:21

In the case you provide an Uri:

Intent action = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
action.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, myUri); 
startActivityForResult(action, CAMERA_RESULT);

and then you retrieve it with (after the tests on requestCode and resultCode):

Bitmap bitmap = BitmapFactory.decodeFile(myUri, options); 

In the other case:

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
startActivityForResult(intent, CAMERA_RESULT); 

and your retrieve it with:

Bundle bundle = intent.getExtras(); 
Bitmap bitmap = (Bitmap) extras.get("data"); 

Here is an expansion of my comment. This snippet of code worked well for me in giving me the pixel data - getting grayscale data and imageview is in my post here

@Override
        public void onClick(View v) {



            Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

            startActivityForResult(Intent.createChooser(intent, "Select Picture"), CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

            }

    });

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    //super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) {
            final ContentResolver cr = getContentResolver();
                    final String[] p1 = new String[] {
                            MediaStore.Images.ImageColumns._ID,
                            MediaStore.Images.ImageColumns.DATE_TAKEN
                    };
                    Cursor c1 = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, p1, null, null, p1[1] + " DESC");
                    if ( c1.moveToFirst() ) {
                        String uristringpic = "content://media/external/images/media/" +c1.getInt(0);
                        Uri uri = Uri.parse(uristringpic);
                        try {
                            Bitmap bm = android.provider.MediaStore.Images.Media.getBitmap(cr, uri);

Hope this helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!