2

I am trying to pick an image from the gallery, convert it to a Bitmap, and display it in an ImageView.

the below code is used to pick image from the gallery

    Intent pickPhoto = new Intent(
            Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(pickPhoto, 1);`

In onActivityResult I am converting it into a Bitmap and displaying it in the ImageView

protected void onActivityResult(int requestCode, int resultCode,
        Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
    switch (requestCode) {
    case 1:
        if (resultCode == RESULT_OK) {
            Uri selectedImage = imageReturnedIntent.getData();
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 4;//returning null for below statement
            bitmap = BitmapFactory.decodeFile(selectedImage.toString(), options);
            productItemImage.setImageBitmap(bitmap);
        }
        break;
    }
}

The value in the selected image Uri is returned as "content://media/external/images/media/3647"

productItemImage is my ImageView to which I am displaying the Bitmap. There is no error but the bitmap is returning null.

Please Help

David Manpearl
  • 11,858
  • 8
  • 50
  • 69
Srikanth Pai
  • 906
  • 3
  • 17
  • 30

1 Answers1

-1

The problem may be your super.onActivityResult() call in your onActivityResult() function.

Here is an answer I wrote last year that gives a complete example of what you want to do, plus allows you to choose from the camera as well as the gallery: Allow user to select camera or gallery for image (This answer has a high score, so I think it will be helpful to you).

Community
  • 1
  • 1
David Manpearl
  • 11,858
  • 8
  • 50
  • 69
  • sorry that was a typing error in the question.. I have corrected it.. but the problem still exists – Srikanth Pai Mar 27 '13 at 17:47
  • Check the edit of my answer, and go here: http://stackoverflow.com/questions/4455558/allow-user-to-select-camera-or-gallery-for-image/12347567#12347567 – David Manpearl Mar 27 '13 at 18:15