Android gets a picture of a directory in SDcard

Source: Internet
Author: User

This article describes how to get all the images in a directory of SDcard in Android development and show them, the following we provide this function is generic, as long as the path can be provided to query the directory of all images of the path information, and saved to a list<string>.

1. Get a collection of directory slices in SDcard

  PublicList<string>getpictures (Final String strpath) {List<String> list =NewArraylist<string>(); File File=NewFile (strpath); File[] Allfiles=File.listfiles (); if(Allfiles = =NULL) {       return NULL; }      for(intK =0; K < Allfiles.length; k++) {Final File fi=Files[i]; if(Fi.isfile ()) {intIDX = Fi.getpath (). LastIndexOf ("."); if(IDX <=0) {                   Continue; } String suffix=Fi.getpath (). substring (IDX); if(Suffix.tolowercase (). Equals (". jpg") ||suffix.tolowercase (). Equals (". JPEG") ||suffix.tolowercase (). Equals (". bmp") ||suffix.tolowercase (). Equals (". PNG") ||suffix.tolowercase (). Equals (". gif") {List.add (Fi.getpath ()); }       }    }    returnlist; }

2. Get the image under the SD card and show

list<string> list = Getpictures (Environment.getexternalstoragedirectory () +""); if(List! =NULL) {log.d (TAG,"list.size ="+list.size ());  for(inti =0; I < list.size (); i++) {Bitmap BM= Bitmapfactory.decodefile (list.Get(i)); inttop = -; if(I >0) {Top+ = Bitmapfactory.decodefile (list.GetI1). GetHeight () +2; } canvas.drawbitmap (BM,0, top, paint); }  }  Else{log.d (TAG,"list is NULL!!!"); }

This article provides two functions, the first function is to get all the pictures in a directory in SDcard, the second function is mainly to display pictures, I hope this article is helpful to Android developers.

Android gets a directory slice in SDcard

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.