Android 读取 assets目录下的文件
- * 读取Assets文件夹中的文件或资源
- * @param context
- * @param fileName assets目录下的文件名
- * @return
- */
- public static Bitmap getImageFromAssetsFile(Context context, String fileName) {
- Bitmap image = null;
- AssetManager am = context.getResources().getAssets();
- try {
- InputStream is = am.open(fileName);
- image = BitmapFactory.decodeStream(is);
- is.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return image;
- }
本文介绍了一种在Android中从Assets目录读取图片的方法。通过使用Context获取AssetManager实例,并利用该实例打开指定文件名的输入流,可以进一步将输入流转换为Bitmap对象,从而实现对Assets文件夹内图片资源的有效利用。
2万+

被折叠的 条评论
为什么被折叠?



