2025年3月29日 星期六 甲辰(龙)年 月廿八 夜 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 编程开发 > 安卓(android)开发

android 从assets中读取文件/图片

时间:02-13来源:作者:点击数:29

以读取图片为例,读取assets下image文件夹中的某个图片

  • /**
  • * 从Assets/image中读取图片
  • * @param fileName 文件名
  • */
  • public static Bitmap getImageFromAssetsFile(Context context, String fileName ) {
  • Bitmap image = null;
  • AssetManager am = context.getResources().getAssets();
  • try {
  • InputStream is = am.open("image/"+fileName+".png");
  • image = BitmapFactory.decodeStream(is);
  • is.close();
  • } catch (IOException e) {
  • e.printStackTrace();
  • }
  • return image;
  • }
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门