Android 获取assets文件夹中的图片资源

来源:互联网 发布:js的onclick事件 编辑:程序博客网 时间:2024/05/16 10:00

此方法可当工具类直接使用:

  1.  * 读取Assets文件夹中的图片资源 
  2.  * @param context 
  3.  * @param fileName 图片名称 
  4.  * @return 
  5.  */ 
  6. public static Bitmap getImageFromAssetsFile(Context context, String fileName) {   
  7.     Bitmap image = null;   
  8.     AssetManager am = context.getResources().getAssets();   
  9.     try {   
  10.         InputStream is = am.open(fileName);   
  11.         image = BitmapFactory.decodeStream(is);   
  12.         is.close();   
  13.     } catch (IOException e) {   
  14.         e.printStackTrace();   
  15.     }   
  16.     return image;   
0 0
原创粉丝点击