Read an Image/file from External storage Android

If i have file abc.jpg on the sdcard then:

String photoPath = Environment.getExternalStorageDirectory() + "/abc.jpg";

and to get bitmap.

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(photoPath, options);

or

Bitmap bitmap1 = BitmapFactory.decodeFile(photoPath);

to avoide out of memory error I suggest you use the below code…

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
final Bitmap b = BitmapFactory.decodeFile(photoPath, options);

To avoid above issue you can use Picasso (A powerful image downloading and caching library for Android)

Documentation

How To?

Picasso.with(context).load("file:///android_asset/DvpvklR.png").into(imageView2);
Picasso.with(context).load(new File(...)).into(imageView3);

Leave a Comment