I am trying to set the background for an ImageView using a saved path. However the following code crashes.
selectSavedImagefromGallery(imagePath);
Here imagePath = "/storage/sdcard0/Downloads/image.jpg" which is a valid path. It works when I set the image choosing it from the gallery. But I would like to save the path so it can be used at anytime.
private void selectSavedImagefromGallery(String savedImagePath) {
Bitmap bm;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(savedImagePath, options);
final int REQUIRED_SIZE = 200;
int scale = 1;
while (options.outWidth / scale / 2 >= REQUIRED_SIZE
&& options.outHeight / scale / 2 >= REQUIRED_SIZE)
scale *= 2;
options.inSampleSize = scale;
options.inJustDecodeBounds = false;
bm = BitmapFactory.decodeFile(savedImagePath, options);
profile_pic.setImageBitmap(bm);
}
The error is being caused by this the last line:
profile_pic.setImageBitmap(bm);
What can I do to make it work?
Thanks.