android 下载图片出现SkImageDecoder::Factory returned null,BitmapFactory.Options压缩
网上有很多说是因为没有采用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压缩的更多相关文章
- Android实战简易教程-第九枪(BitmapFactory.Options对资源图片进行缩放)
我们知道,我们编写的应用程序都是有一定内存限制的.程序占用了过高的内存就easy出现OOM(OutOfMemory)异常.因此在展示高分辨率图片的时候,最好先将图片进行压缩,压缩后的图片大小应该和用来 ...
- BitmapFactory.Options.inSampleSize 的使用方法
BitmapFactory.decodeFile(imageFile); 用BitmapFactory解码一张图片时.有时会遇到该错误. 这往往是因为图片过大造成的. 要想正常使用,则须要分配更少的内 ...
- android 高德地图API 之 java.lang.UnsatisfiedLinkError: Couldn't load amapv3: findLibrary returned null错误
错误场景: 运行android app时,在运行到调用高德地图API时,出现 “java.lang.UnsatisfiedLinkError: Couldn't load amapv3: findLi ...
- findlibrary returned null产生的联想,Android ndk开发打包时我们应该怎样注意平台的兼容(x86,arm,arm-v7a)
非常多朋友在开发Android JNI的的时候,会遇到findlibrary returned null的错误,由于某种原因,so没有打包到apk中.以下浅析下引起该错误的原因以及平台兼容性问题. A ...
- Android中运行的错误:java.lang.UnsatisfiedLinkError: Couldn't load locSDK3: findLibrary returned null.
---恢复内容开始--- 明明已经加入了liblocSDK3.so,但总是无法定位.提示错误java.lang.UnsatisfiedLinkError: Couldn't load locSDK3: ...
- Android中执行的错误:java.lang.UnsatisfiedLinkError: Couldn't load locSDK3: findLibrary returned null.
今天在使用百度地图的时候执行发现报错: 明明已经增加了liblocSDK3.so.但总是无法定位.提示错误java.lang.UnsatisfiedLinkError: Couldn't load l ...
- Android学习笔记之BitmapFactory.Options实现图片资源的加载...
PS:小项目总算是做完了...历经20多天...素材,设计,以及实现全由自己完成...心力憔悴啊...该写写博客记录一下学习到的东西了... 学习内容: 1.使用BitmapFactory.Optio ...
- Android BitmapFactory图片压缩处理(大位图二次採样压缩处理)
Android实际开发中.在载入大量图片的时候.比方ViewPager.GridView.ListView中,载入了大量的比較大图片就easy出现OOM(内存溢出)的异常,这是由于一个应用的最大内存使 ...
- Android 下载文件及写入SD卡
Android 下载文件及写入SD卡,实例代码 <?xml version="1.0" encoding="utf-8"?> <LinearL ...
随机推荐
- 基本的Web控件三
基本的Web控件用法一 ListBox控件 页面布局: <div> <h1>ListBox控件</h1> 学生列表: <br/> <asp:Lis ...
- url中文参数解决方案
首先,弄清楚为什么url传递中文会转码或者乱码,以及http头 contentType="text/html; charset=GBK" 的作用. html代码会经过web服务器, ...
- Mysql远程登录授权
1.改表法. 请使用mysql管理工具,如:SQLyog Enterprise 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑使用mysql管理工 ...
- 代码快捷键的设置读取App.config方法
附件下载:http://files.cnblogs.com/files/qtiger/ShortcutAchieve.zip 代码实现最重要(增加引用using System.Configuratio ...
- Outlook 2007无法打开链接"由于本机的限制 该操作已被取消"
编写人:CC阿爸 2014-2-17 近来在日常维护中,经常性的遇到用户在outlook中打开链接,提示[由于本机的限制,该操作已被取消],第一次的在网上搜索到解决办法后, 第二次再处理时,又没能记住 ...
- [译]MongoDB 3.0发布说明
原文来自:http://docs.mongodb.org/manual/release-notes/3.0/ 2015年3月3日 MongoDB 3.0现已可供使用.关键新特性包括支持WiredTig ...
- 如何在Netbeans中查看TODO项
以下要说的内容可能不起眼,但本人在找的时候着实费了一番功夫,个人感觉网上说的不着点,就在这儿有针对性地记录下来操作流程吧. 关于TODO的作用这里不做说明,在IDE中编写代码时,我们总会用到TODO, ...
- mybatis动态sql中的trim标签的使用(转)
trim标记是一个格式化的标记,可以完成set或者是where标记的功能,如下代码: 1. select * from user <trim prefix="WHERE" p ...
- AsyncTask的简单使用
package com.zzw.life; import android.app.Activity; import android.os.AsyncTask; import android.os.Bu ...
- IOS学习4
---恢复内容开始--- UIScrollView 屏幕展示有限,超出一个屏时用户可滚动查看过多部分.UIView不具备滚动功能. -取消autolayout -设置CGSize contentSiz ...