展会信息港展会大全

Android获取SD卡根目录下图片
来源:互联网   发布日期:2016-01-13 21:59:42   浏览:3373次  

导读:/*** Get pictures under directory of strPath* @param strPath* @return list*/public ListSTRING getPictures(final String strPath) {ListSTRING list = new ArrayListSTRING();Fi......

/**

* Get pictures under directory of strPath

* @param strPath

* @return list

*/

public List<STRING> getPictures(final String strPath) {

List<STRING> list = new ArrayList<STRING>();

File file = new File(strPath);

File[] files = file.listFiles();

if (files == null) {

return null;

}

for(int i = 0; i < files.length; i++) {

final File f = files[i];

if(f.isFile()) {

try{

int idx = f.getPath().lastIndexOf(".");

if (idx <= 0) {

continue;

}

String suffix = f.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(f.getPath());

}

} catch(Exception e) {

e.printStackTrace();

}

}

}

return list;

}

2.调用上述方法获取sd卡下的图片并显示

List<STRING> list = getPictures(Environment.getExternalStorageDirectory() + "");

if (list != null) {

Log.d(TAG, "list.size = " + list.size());

for (int i = 0; i < list.size(); i++) {

Bitmap bm = BitmapFactory.decodeFile(list.get(i));

int top = 30;

if (i > 0) {

top += BitmapFactory.decodeFile(list.get(i - 1)).getHeight() + 2;

}

canvas.drawBitmap(bm, 0, top, paint);

}

}

else {

Log.d(TAG, "list is null!!!");

}

赞助本站

人工智能实验室

相关热词: 根目录 SD卡 图片

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港