30

I have a image stored in SD card of my phone. I want to show it in a image view. I know the location of the file. On the oncreate of the activity is there a simple way to say something like

ImageView img = (ImageView) findViewById(R.id.imageView1);    
String path = Environment.getExternalStorageDirectory().toString() "Images/image.jpg";     
img.setsrc = path ;

Please let me know if there is any way to do this. Thank you.

ingsaurabh
  • 15,249
  • 7
  • 52
  • 81
Vinod
  • 31,933
  • 35
  • 96
  • 119

2 Answers2

88
Bitmap bmp = BitmapFactory.decodeFile(pathName);
ImageView img;
img.setImageBitmap(bmp);
Yash Khare
  • 355
  • 2
  • 10
Egor
  • 39,695
  • 10
  • 113
  • 130
23

I have this snippet that may help:

File imageFile = new  File("/sdcard/example/image.jpg"); 
if(imageFile.exists()){
    ImageView imageView= (ImageView) findViewById(R.id.imageviewTest);
    imageView.setImageBitmap(BitmapFactory.decodeFile(imageFile.getAbsolutePath()));
}

:)

MBH
  • 16,271
  • 19
  • 99
  • 149