Set Imageview to show image in sdcard?

47,863

Solution 1

Bitmap bmp = BitmapFactory.decodeFile(pathName);
ImageView img;
img.setImageBitmap(bmp);

Hope this helps.

Solution 2

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()));
}

:)

Share:
47,863
Vinod
Author by

Vinod

Updated on November 28, 2020

Comments

  • Vinod
    Vinod over 3 years

    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.

  • Suhas Bachewar
    Suhas Bachewar over 8 years
    I have problem to load bitmap of image size 1.98 MB , camera Picture size 16M Pixels.
  • Ahmed
    Ahmed over 8 years
    Do we need to call recycle on bitmap if it is constantly being created and set on ImageView ?
  • user3560827
    user3560827 almost 8 years
    Image is lost when activity ends, anyway to make it permanent, or do I have to write path string to sdcard as text and read from it each time?