BitmapFactory.decodeStream 返回值为null的问题
来源:互联网 发布:南华大学船山学院 知乎 编辑:程序博客网 时间:2024/05/22 15:32
public void download(String u) throws Exception { URL url = new URL(u); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5 * 1000); conn.setRequestMethod("GET"); if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { InputStream is = conn.getInputStream(); Bitmap bitmap = BitmapFactory.decodeStream(is); } }
上面的代码中 BitmapFactory.decodeStream 返回了null,
后来看了一篇帖子说 android 1.6版本会有这样一个bug,虽然我用的不是1.6版本的,但是决定试一下,用高手建议的方法发现问题解决了
我的最终解决办法是:
public void download(String u) throws Exception {URL url = new URL(u);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setConnectTimeout(5 * 1000);conn.setRequestMethod("GET");if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {InputStream is = conn.getInputStream();byte[] data = reads(is);Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);}}public static byte[] reads(InputStream ins) throws Exception {ByteArrayOutputStream outStream = new ByteArrayOutputStream();byte[] b = new byte[1024];int len = 0;while ((len = ins.read(b)) != -1) {outStream.write(b, 0, len);}outStream.close();ins.close();return outStream.toByteArray();}
- BitmapFactory.decodeStream 返回值为null的问题
- BitmapFactory.decodeStream返回null
- BitmapFactory.decodeStream(inputStream,null,options)返回为null
- BitmapFactory.decodeFactory.decodeStream(InputStream xx)返回为null
- Android异步从网络加载图片BitmapFactory.decodeStream 返回null的问题
- Android异步加载图片资源,BitmapFactory.decodeStream返回null的问题
- 安卓BitmapFactory.decodeStream()返回null的问题解决方法
- BitmapFactory.decodeStream方法返回null的错误分析
- BitmapFactory.decodeStream方法返回null的错误分析
- 安卓BitmapFactory.decodeStream()返回null的问题解决方法
- 解决android BitmapFactory.decodeStream()返回null
- Android 压缩网络上的图片BitmapFactory.decodeStream()返回为空的问题
- android BitmapFactory.decodeFile()返回为null问题
- BitmapFactory.decodeStream 问题
- BitmapFactory.decodeStream使用问题
- BitmapFactory的decodeStream()方法导致InputStream失效的问题
- BitmapFactory.decodeStream使用inJustDecodeBounds参数解析网络流的问题
- 调用 BitmapFactory.decodeByteArray 函数返回 null 值
- jsp,xml自动提示
- ios,scrollview 或 tableview中实现上滚隐藏tabbar,下滚出现tabbar
- 新时代下编译老古董之win7编译eclipse3.2
- sharepoint入门
- java 中的 class path, package, jar 等基本问题
- BitmapFactory.decodeStream 返回值为null的问题
- 使用ViewSwitcher实现ListView的数据动态加载[学习]
- KMP算法详解(精华)
- 重建二叉树(1)
- android NDK 开发实例
- spring web mvc环境下使用dwr
- 集群配置及应用部署文档
- 【等待他们的必然就是痛苦】
- 几个简单的数据点平滑处理算法