Friday, 27 April 2012

How to show the image stored in the sdcard on the Imageview

Many a times there is a requirement when we want to show the image on the imageview that is currently stored on the sdcard.

Step 1:- First out get the actual path of the image stored on sd card.for e.g -

 /mnt/sdcard/peng.jpg


Step 2 :- Make the use of the File class of java and then use the File reference to show the image on the Imageview. for e.g

File imageFile = new File("/mnt/sdcard/peng.jpg");


Step 3  :- Now use this refrence to show the image with the help Bitmap.


Bitmap myBitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());


Imageview myView = (Imageview)findViewById(R.id.main);


myView.setImageBitmap(myBitmap);




That's all. It will show the particular image that is stored on the sdcard on the Imageview.

No comments:

Post a Comment