您的位置:首页 > 移动开发 > Android开发

Android 读取Assets中图片

2016-11-11 18:37 393 查看
注:从非Activity中调用此方法需要传入Context对象。

/**
* 从Assets中读取图片
* @param fileName
* @param context
* @return bitmap
*/
public static Bitmap getImageFromAssetsFile(String fileName, Context context) {
Bitmap image = null;
AssetManager am = context.getResources().getAssets();
try {
InputStream is = am.open(fileName.substring(7));//去除文件名中无用字符
image = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return image;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: