android中加载图片decodeStream导致内存溢出浅谈

项目开发中难免会用到图片资源加载,android本身提供了图片解析功能BitmapFactory,里面有多种多样的解析方案,不赘述了,写这篇文章主要是因为遇到了一个比较难懂的问题,分享出来大家如果知道原因请回复。

1)最简单的加载方案肯定就是decodestream了,我们把图片资源放到assets文件夹下,程序运行过程中通过assetsmanager打开流进行加载资源,可以得到bitmap对象,当然这种手段是最简单的一种方案。

2)有时候我们会遇到一些大的图片加载,那么大图片加载必然会出现内存问题,这时候我们就要考虑到图片加载带来的内存消耗隐患包括会出现oom问题,解决之道当然在于另一个重载函数decodestream,参数有三个

/**
     * Decode an input stream into a bitmap. If the input stream is null, or
     * cannot be used to decode a bitmap, the function returns null.
     * The stream's position will be where ever it was after the encoded data
     * was read.
     *
     * @param is The input stream that holds the raw data to be decoded into a
     *           bitmap.
     * @param outPadding If not null, return the padding rect for the bitmap if
     *                   it exists, otherwise set padding to
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值