I am trying to scale my images down to smaller size I was loading them as they were into an imageview and I started getting a “bitmap size exceeds VM budget” exception. On the other hand if I get the thumbnails instead of the actual images and show them it runs smooth. But I need the URIs of the actual images for later use which I can’t get if I straight away load the thumbnails.
After looking around, I found a way, but it’s not working.
Code:
Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, name);
uriList.add(uri.getPath());
File image = new File(uri.getPath());
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap actualBitmap = BitmapFactory.decodeFile(image.getPath(), options);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(actualBitmap, image_width, image_height, false);
iv.setImageBitmap(scaledBitmap);
The part where I get the actualBitmap returns null, and so the imageview is empty. If I print uri.getpath() it gives:
/external/images/media//sdcard/dcim/Camera/imagename.jpg
My question is, is this the right approach? If it is, what am I doing wrong and if it’s not can someone please point me in the right direction.
try with the following code