Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Imageview to show image in sdcard?

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.

like image 269
Vinod Avatar asked Jun 03 '11 08:06

Vinod


People also ask

Can ImageView display video?

You can add ImageView and VideoView in RelativeLayout and set ImageView to invisible and VideoView to visible and vice-versa and you can play video on onClick.

Which attribute is used to set an image in ImageView?

src: src is an attribute used to set a source file or you can say image in your imageview to make your layout attractive.


2 Answers

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

Hope this helps.

like image 97
Egor Avatar answered Sep 22 '22 04:09

Egor


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

:)

like image 32
MBH Avatar answered Sep 19 '22 04:09

MBH