0

I use this to let the user pick an image from gallery:

Intent i = new Intent(
                        Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                i.setType("image/*");
                i.putExtra("crop", "true");
                i.putExtra("scale", true);
                i.putExtra("return-data", true);
                startActivityForResult(i, RESULT_LOAD_IMAGE);

Then it will be displayed in an ImageView:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {

            final Bundle extras = data.getExtras();
            Bitmap photo = extras.getParcelable("data");

            ImageView imageView = (ImageView) findViewById(R.id.image);
            imageView.setImageBitmap(photo);

        }
    }

It works but the picture now has a bad quality. How to fix this?

1 Answers1

0

You shouldn't specify any of those extras because they are device-dependent. Just do this:

Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, RESULT_LOAD_IMAGE);

and

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK)
    {
        Uri selectedImage = data.getData();
        //load Uri into ImageView
    }
}

I would look into using a library like Picasso to load the images instead of just doing imageView.setImageBitmap(photo) if your app is image intensive.

ashishduh
  • 6,629
  • 3
  • 30
  • 35
  • Without the extras it works fine, the problem is the user should be able to resize the picture. Thanks for the library by the way. – user3557747 May 01 '14 at 19:45
  • Well the source of your problem is that you're being returned a thumbnail, which you're probably sizing up to fit the imageview, which is why the quality looks bad. If you set the ImageView's size parameters to be `wrap_content` you'll see that you're receiving a thumbnail. I'm not sure how to fix that issue as I've never used the pick intent with crop/size parameters before, sorry. – ashishduh May 01 '14 at 19:46