android高效读取大图片 防止OOM
16lz
2022-04-23
工具方法
public static Bitmap getImageFromAssetsFile1(Context context, String fileName) {Bitmap image = null; ByteArrayOutputStream outputStream=new ByteArrayOutputStream();byte[] bytes = new byte[1024];//读取 int len=0;AssetManager am = context.getResources().getAssets();try {InputStream is = am.open(fileName);while((len=is.read(bytes))!=-1){outputStream.write(bytes, 0, len);//写入}byte[] result=outputStream.toByteArray();//声明字节数组image = BitmapFactory.decodeByteArray(result, 0, result. length);} catch (IOException e) { // TODO Auto-generated catch blocke.printStackTrace();}return image;}
更多相关文章
- Android创建文件夹及文件并写入数据
- 第一章:初入Android大门(Gallery拖动相片特效)
- Unity同步加载Android里的StreamingAssets里的文件
- Android列表实现(1)_数组列表
- 游戏开发4_01 数据存储--io
- android 网络图片与网页读取
- 任务栏一键删除 Recent APP
- Android(安卓)InputStream与String,Byte之间互转
- No 98 · Android(安卓)下载文件及写入SD卡(摘)