1.获取某个目录下图片路径list
2.调用上述方法获取sd卡下的图片并显示
[代码]java代码:
01 |
/** |
02 |
*
Get pictures under directory of strPath |
03 |
*
@param strPath |
04 |
*
@return list |
05 |
*/ |
06 |
public List
getPictures( final String
strPath) { |
07 |
List
list = new ArrayList(); |
08 |
|
09 |
File
file = new File(strPath); |
10 |
File[]
files = file.listFiles(); |
11 |
|
12 |
if (files
== null )
{ |
13 |
return null ; |
14 |
} |
15 |
|
16 |
for ( int i
= 0 ;
i < files.length; i++) { |
17 |
final File
f = files[i]; |
18 |
if (f.isFile())
{ |
19 |
try { |
20 |
int idx
= f.getPath().lastIndexOf( "." ); |
21 |
if (idx
<= 0 )
{ |
22 |
continue ; |
23 |
} |
24 |
String
suffix = f.getPath().substring(idx); |
25 |
if (suffix.toLowerCase().equals( ".jpg" )
|| |
26 |
suffix.toLowerCase().equals( ".jpeg" )
|| |
27 |
suffix.toLowerCase().equals( ".bmp" )
|| |
28 |
suffix.toLowerCase().equals( ".png" )
|| |
29 |
suffix.toLowerCase().equals( ".gif" )
) |
30 |
{ |
31 |
list.add(f.getPath()); |
32 |
} |
33 |
} catch (Exception
e) { |
34 |
e.printStackTrace(); |
35 |
} |
36 |
} |
37 |
} |
38 |
|
39 |
return list; |
40 |
} |
[代码]java代码:
01 |
List
list = getPictures(Environment.getExternalStorageDirectory() + "" ); |
02 |
if (list
!= null )
{ |
03 |
Log.d(TAG, "list.size
= " +
list.size()); |
04 |
for ( int i
= 0 ;
i < list.size(); i++) { |
05 |
Bitmap
bm = BitmapFactory.decodeFile(list.get(i)); |
06 |
int top
= 30 ; |
07 |
if (i
> 0 )
{ |
08 |
top
+= BitmapFactory.decodeFile(list.get(i - 1 )).getHeight()
+ 2 ; |
09 |
} |
10 |
canvas.drawBitmap(bm, 0 ,
top, paint); |
11 |
} |
12 |
} |
13 |
else { |
14 |
Log.d(TAG, "list
is null!!!" ); |