0

I'm trying to populate a Gallery view with images from a folder in the SDcard. I read the Gallery tutorial on Android Dev seen here: http://developer.android.com/resources/tutorials/views/hello-gallery.html, and can get it working with images from the drawable folder of my project.

My question is: how can I get an array of files from the Environment.getExternalStorageDirectory()+File.separator+"MyPictureDirectory folder, and then display them in the Gallery? Thanks!

1 Answer 1

1

Try the following,

File file = new File( Environment.getExternalStorageDirectory()+File.separator+"MyPictureDirectory"+File.separator); File imageList[] = file.listFiles(); for(int i=0;i<imageList.length;i++) { //Add images in Gallery from imageList } 

To set image from file path:

File imgFile = new File(imagefilepath); if(imgFile.exists()){ Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); ImageView myImage = (ImageView) findViewById(R.id.imageviewTest); myImage.setImageBitmap(myBitmap); } 
Sign up to request clarification or add additional context in comments.

4 Comments

how do i set file object to imageview?
i have tried all the methods available but still my gridview lags because of bitmap decoading
@Siddhesh: Are you getting any error,whats your status Siddhesh?
no errors... code is running perfectly but just that grid lags because cr.moveToPosition(position); int imageID = cr.getInt(columnIndex); Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) ); String url = uri.toString(); int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length())); Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null); picturesView.setImageBitmap(b); in getView()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.