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