网上有很多说是因为没有采用HttpClient造成的,尼玛,我改成了HttpClient 请求图片之后还是会出现SkImageDecoder::Factory returned null,

但是直接使用

bitmap = BitmapFactory.decodeStream(is);  是正常的,但解决不了图片大内存溢出的问题

解决办法:

重新获取一次流,注意看代码(红色部分):

/**
* 根据网络url获取bitmap对象
* @param url
* @param width 要获取的宽度
* @param height 要获取的高度 防止内存溢出
* @return
*/
public static Bitmap returnBitMap(String url, int width,int height) { Bitmap bitmap = null;
try {
HttpGet httpRequest = new HttpGet(url);
Log.d("returnbitmap", "url="+url);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(entity);
InputStream is = bufferedHttpEntity.getContent();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; //只获取图片的高宽
int scale = 1;
BitmapFactory.decodeStream(is,null,options);
int w = options.outWidth;
int h = options.outHeight;
Log.d("returnbitmap", "w="+w+";h="+h+";width="+width+";height="+height);
while(true)
{
if ((width>0 && w < width) || (height>0 && h < height))
{
break;
}
w /= 2;
h /= 2;
scale *= 2;
}
options.inJustDecodeBounds = false;
options.inSampleSize = scale;
is = bufferedHttpEntity.getContent();//重新获取流
bitmap = BitmapFactory.decodeStream(is,null,options);
Log.d("returnbitmap", "bitmap="+bitmap+(bitmap==null?"bitmap is null":"bitmap is not null"));
is.close();
} catch (IOException e) {
e.printStackTrace();
}
catch (OutOfMemoryError e) {
e.printStackTrace();
}
return bitmap;
}

这样就可以正常下载并显示了,噢耶!!!

android 下载图片出现SkImageDecoder::Factory returned null,BitmapFactory.Options压缩的更多相关文章

  1. Android实战简易教程-第九枪(BitmapFactory.Options对资源图片进行缩放)

    我们知道,我们编写的应用程序都是有一定内存限制的.程序占用了过高的内存就easy出现OOM(OutOfMemory)异常.因此在展示高分辨率图片的时候,最好先将图片进行压缩,压缩后的图片大小应该和用来 ...

  2. BitmapFactory.Options.inSampleSize 的使用方法

    BitmapFactory.decodeFile(imageFile); 用BitmapFactory解码一张图片时.有时会遇到该错误. 这往往是因为图片过大造成的. 要想正常使用,则须要分配更少的内 ...

  3. android 高德地图API 之 java.lang.UnsatisfiedLinkError: Couldn't load amapv3: findLibrary returned null错误

    错误场景: 运行android app时,在运行到调用高德地图API时,出现 “java.lang.UnsatisfiedLinkError: Couldn't load amapv3: findLi ...

  4. findlibrary returned null产生的联想,Android ndk开发打包时我们应该怎样注意平台的兼容(x86,arm,arm-v7a)

    非常多朋友在开发Android JNI的的时候,会遇到findlibrary returned null的错误,由于某种原因,so没有打包到apk中.以下浅析下引起该错误的原因以及平台兼容性问题. A ...

  5. Android中运行的错误:java.lang.UnsatisfiedLinkError: Couldn't load locSDK3: findLibrary returned null.

    ---恢复内容开始--- 明明已经加入了liblocSDK3.so,但总是无法定位.提示错误java.lang.UnsatisfiedLinkError: Couldn't load locSDK3: ...

  6. Android中执行的错误:java.lang.UnsatisfiedLinkError: Couldn't load locSDK3: findLibrary returned null.

    今天在使用百度地图的时候执行发现报错: 明明已经增加了liblocSDK3.so.但总是无法定位.提示错误java.lang.UnsatisfiedLinkError: Couldn't load l ...

  7. Android学习笔记之BitmapFactory.Options实现图片资源的加载...

    PS:小项目总算是做完了...历经20多天...素材,设计,以及实现全由自己完成...心力憔悴啊...该写写博客记录一下学习到的东西了... 学习内容: 1.使用BitmapFactory.Optio ...

  8. Android BitmapFactory图片压缩处理(大位图二次採样压缩处理)

    Android实际开发中.在载入大量图片的时候.比方ViewPager.GridView.ListView中,载入了大量的比較大图片就easy出现OOM(内存溢出)的异常,这是由于一个应用的最大内存使 ...

  9. Android 下载文件及写入SD卡

    Android 下载文件及写入SD卡,实例代码 <?xml version="1.0" encoding="utf-8"?> <LinearL ...

随机推荐

  1. GUI_DOWNLOAD参数说明

    对FUNCTION: GUI_DOWNLOAD中某些参数的用法.       call function 'GUI_DOWNLOAD'     exporting *     BIN_FILESIZE ...

  2. Ubuntu下fcitx安装。(ibus不会用)

    1 安装命令: sudo apt-get install fcitx-table-wbpy 2 然后将语言支持中的键盘输入方式系统选项,选为fcitx. 3 注销系统后即可使用.

  3. Tomcat启动过程(三):从SocketProcessor到Container

    1.Http11Protocol中的内部类Http11ConnectionHandler,执行其process方法 if (processor == null) { processor = creat ...

  4. IOS 支付功能的实现

    支付宝是第三方支付平台,简单来说就是协调客户,商户,银行三者关系的方便平台 使用支付宝进行一个完整的支付功能,大致有以下步骤: a 与支付宝进行签约,获得商户ID(partner)和账号ID(sell ...

  5. ViewGroup 和 View 事件传递及处理小谈

    前言 在自定义组件的时候少不了会去处理一些事件相关的东西,关于事件这块网上有很多文章,有说的对的也有说的不对的,我在理解的时候也有过一段时间的迷惑,现在把自己理解的东西写下来,给有相同疑问的朋友提供些 ...

  6. 有关c#装箱和拆箱知识整理

    c#装箱和拆箱知识,装箱和拆箱是一个抽象的概念. 1.装箱和拆箱是一个抽象的概念  2.装箱是将值类型转换为引用类型 : 拆箱是将引用类型转换为值类型 利用装箱和拆箱功能,可通过允许值类型的任何值与O ...

  7. SVN客户端解决authorization failed问题

    遇到authorization failed问题 进人 [root@localhost conf]# pwd /opt/svndata/shell/conf [root@localhost conf] ...

  8. Modoer列表页性能分析及优化

    在 http://www.modoer.org/beijing/item/list-8 的页面中,会执行以下2个sql SELECT s.sid,pid,catid,domain,name,avgso ...

  9. PHP通过字符串调用函数

    1. call_user_func function a($b,$c){ echo $b; echo $c; } call_user_func('a', "111","2 ...

  10. C++排列对称串

    题目内容:字符串有些是对称的,有些是不对称的,请将那些对称的字符串按从小到大的顺序输出.字符串先以长度论大小,如果长度相同,再以ASCII码值为排序标准. 输入描述:输入数据中含有一些字符串(1< ...