Android 獲取assets文件夾中的圖片資源

此方法可當工具類直接使用:

  1.  * 讀取Assets文件夾中的圖片資源 
  2.  * @param context 
  3.  * @param fileName 圖片名稱 
  4.  * @return 
  5.  */ 
  6. public static Bitmap getImageFromAssetsFile(Context context, String fileName) {   
  7.     Bitmap p_w_picpath = null;   
  8.     AssetManager am = context.getResources().getAssets();   
  9.     try {   
  10.         InputStream is = am.open(fileName);   
  11.         p_w_picpath = BitmapFactory.decodeStream(is);   
  12.         is.close();   
  13.     } catch (IOException e) {   
  14.         e.printStackTrace();   
  15.     }   
  16.     return p_w_picpath;   
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章