是用两个方法从网络上读取bitmap展示
1. BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inTempStorage = new byte[12 * 1024];
bitmap = BitmapFactory.decodeStream(bis, null, opts);
2. BufferedInputStream bis = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
bis = new BufferedInputStream(is, BUFFER_SIZE);
int i = -1;
byte buf[] = new byte[4 * 1024];
while ((i = bis.read(buf)) != -1) {
out.write(buf, 0, i);
}
byte imgData[] = out.toByteArray();
bitmap = BitmapFactory.decodeByteArray(imgData, 0,
imgData.length);
很明显的前者OOM的概率几倍于后者。
还请达人给解疑答惑,谢谢!
1. BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inTempStorage = new byte[12 * 1024];
bitmap = BitmapFactory.decodeStream(bis, null, opts);
2. BufferedInputStream bis = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
bis = new BufferedInputStream(is, BUFFER_SIZE);
int i = -1;
byte buf[] = new byte[4 * 1024];
while ((i = bis.read(buf)) != -1) {
out.write(buf, 0, i);
}
byte imgData[] = out.toByteArray();
bitmap = BitmapFactory.decodeByteArray(imgData, 0,
imgData.length);
很明显的前者OOM的概率几倍于后者。
还请达人给解疑答惑,谢谢!
其实从网络使用inputstream是非常耗费的 比如我上传了一张1MB的图片 实际上用流读的时候会翻倍增长而消耗的就是你应用的内存http://my.eoe.cn/935878/archive/3705.html
图片不大,图片很小,就是图片数量多些,重复几次,直接通过bis生成的bitmap方式会oom的快些!