InputStream open(String fileName);//以顺序读取模式打开文件,默认模式为ACCESS_STREAMING
InputStream open(String fileName, int accessMode);//以指定模式打开文件。读取模式有以下几种:
//ACCESS_UNKNOWN : 未指定具体的读取模式
//ACCESS_RANDOM : 随机读取
//ACCESS_STREAMING : 顺序读取
//ACCESS_BUFFER : 缓存读取
imageView = (ImageView) findViewById(R.id.iv);
AssetManager manager = getResources().getAssets();
List<Map<
String,
Object>> catelist =
new ArrayList<Map<
String,
Object>>();
String[] list_image =
null;
try {
list_image = manager.list(
"bannerjpeg");
}
catch (IOException e) {
e.printStackTrace();
}
for(int i =
0;i<list_image.length;i++) {
InputStream open =
null;
try {
String imagepath =
"bannerjpeg/"+list_image[i];
open = manager.open(imagepath);
Bitmap bitmap = BitmapFactory.decodeStream(open);
Map<
String,
Object> map =
new TreeMap<
String,
Object>();
map.put(
""+i, bitmap);
catelist.add(map);
}
catch (IOException e) {
e.printStackTrace();
}
finally {
if(open!=
null) {
try {
open.close();
}
catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
bitmaps =
new ArrayList<Bitmap>();
for(int i =
0;i<catelist.size();i++) {
Bitmap bitmap = (Bitmap) catelist.get(i).get(
""+i);
bitmaps.add(bitmap);
}
imageView.setImageBitmap(bitmaps.get(
3));
}
最后要注意: 如果我们不在 assets目录下创建一个子目录的话 assets目录下 会有隐藏文件 (其实我只是放了 4张图片 )如下:
转载请注明原文地址: https://ju.6miu.com/read-668111.html