Get a full quality camera image

When I take a picture with the camera and then I want to show this image in the ImageView, I followed the following method:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PHOTO_REQUEST_FRAG);

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case PICK_IMAGE_REQUEST_FRAG:
            if (resultCode == getActivity().RESULT_OK && data != null) {

                Bitmap srcBmp = (Bitmap) data.getExtras().get("data");

                ... (process image to scale size and rotate if necesary)

                pic_view.setImageBitmap(srcBmp);
            }
    }
}

      

I was getting the image and displaying it in the ImageView correctly, but I realized that the resulting image was of very low quality. After some research, I found that the image obtained with this method is a thumbnail image of the captured image. So I changed the code following some guidance from other SO posts saying this:

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "Pictures/timeStamp.jpg";
takenPicUri = Uri.fromFile(new File(imageFilePath));
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, takenPicUri);
startActivityForResult(intent, TAKE_PHOTO_REQUEST_FRAG);

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case PICK_IMAGE_REQUEST_FRAG:
            if (resultCode == getActivity().RESULT_OK && data != null) {

                Bitmap srcBmp = BitmapFactory.decodeStream(getActivity().getContentResolver().openInputStream(uri), null, null);

                ... (process image to scale size and rotate if necesary)

                pic_view.setImageBitmap(srcBmp);
            }
    }
}

      

But now the image is not showing in ImageView (pic_view). In other posts I've read, people report that this method worked for them, but doesn't work for me. Am I forgetting something or is there something wrong?

+3


source to share


1 answer


Ok, I read in old posts that this way of doing it might cause problems because there is some kind of bug related to this, but this is the only way I have achieved to get it to work.

As simple as:



Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PHOTO_REQUEST_FRAG);

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case PICK_IMAGE_REQUEST_FRAG:
            if (resultCode == getActivity().RESULT_OK && data != null) {

                Uri selectedImageUri = data.getData();
                Bitmap srcBmp = BitmapFactory.decodeStream(getActivity().getContentResolver().openInputStream(uri), null, null);

                ... (process image to scale size and rotate if necesary)

                pic_view.setImageBitmap(srcBmp);
            }
    }
}

      

This method works with Android 5.0 and 4.4.4.

+2


source







All Articles