How To Load Image From Sdcard In Android

Steps to load image from sdcard in android

Step 1 — Get the exact image path in sdcard

Step 2 — Create Bitmap from the image path

options.inSampleSize = 8;
final Bitmap b = BitmapFactory.decodeFile("/mnt/sdcard/DCIM/100ANDRO/DSC_0002.jpg",options)

Step 3 — Set the bitmap into imageview

iv.setImageBitmap(b);

Load Image From Sdcard Example

public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView iv = (ImageView)findViewById(R.id.imageView1);
BitmapFactory.Options options = new BitmapFactory.Options();
// will results in a much smaller image than the original
options.inSampleSize = 8;
final Bitmap b = BitmapFactory.decodeFile("/mnt/sdcard/DCIM/100ANDRO/DSC_0002.jpg", options);
iv.setImageBitmap(b);
}
}

Lead Software Engineer @htcindia | @github contributor | Blog writer @howtodoandroid | Quick Learner