Solution to BitmapFactory decodeStream null
2011-10-25 14:02
316 查看
最近遇到从网络上下载图片,解码一直是null的问题:
开始时以为TimeOut太短,或者buffersize太小的问题,修改后仍然没有解决问题,记得同样的方法以前下载图片挺正常的,Google之,找到了问题的答案,起码解决了我的问题。
网上类似的问题:
http://stackoverflow.com/questions/3802820/bitmapfactory-decodestream-always-returns-null-and-skia-decoder-shows-decode-ret
原来是系统bug,2.1版本中仍存在这个问题:
http://code.google.com/p/android/issues/detail?id=6066
The problem was indeed in the calls to the InputStream skip() method.
解决方法:
或者另外建个类。
以前的代码改为:
遇到同样问题的童鞋可以参考。
..... Bitmap bitmap=BitmapFactory.decodeStream(inputStream); ....
开始时以为TimeOut太短,或者buffersize太小的问题,修改后仍然没有解决问题,记得同样的方法以前下载图片挺正常的,Google之,找到了问题的答案,起码解决了我的问题。
网上类似的问题:
http://stackoverflow.com/questions/3802820/bitmapfactory-decodestream-always-returns-null-and-skia-decoder-shows-decode-ret
原来是系统bug,2.1版本中仍存在这个问题:
http://code.google.com/p/android/issues/detail?id=6066
The problem was indeed in the calls to the InputStream skip() method.
解决方法:
static class FlushedInputStream extends FilterInputStream { public FlushedInputStream(InputStream inputStream) { super(inputStream); } @Override public long skip(long n) throws IOException { long totalBytesSkipped = 0L; while (totalBytesSkipped < n) { long bytesSkipped = in.skip(n - totalBytesSkipped); if (bytesSkipped == 0L) { int bytes = read(); if (bytes < 0) { break; // we reached EOF } else { bytesSkipped = 1; // we read one byte } } totalBytesSkipped += bytesSkipped; } return totalBytesSkipped; } }
或者另外建个类。
以前的代码改为:
Bitmap bitmap = BitmapFactory.decodeStream(new FlushedInputStream(inputStream));
遇到同样问题的童鞋可以参考。
相关文章推荐
- 安卓BitmapFactory.decodeStream()返回null的问题解决方法
- BitmapFactory.decodeStream。报错:SkImageDecoder::Factory returned null 原因及解决方法
- BitmapFactory.decodeStream(inputStream,null,options)返回为null
- BitmapFactory.decodeStream返回null
- BitmapFactory.decodeStream()获取bitmap返回null
- BitmapFactory.decodeFactory.decodeStream(InputStream xx)返回为null
- BitmapFactory.decodeStream(inputStream)返回null的解决方法
- Android异步从网络加载图片BitmapFactory.decodeStream 返回null的问题
- Android异步加载图片资源,BitmapFactory.decodeStream返回null的问题
- BitmapFactory.decodeStream方法返回null的错误分析
- BitmapFactory.decodeStream 返回值为null的问题
- 安卓BitmapFactory.decodeStream()返回null的问题解决方法
- 解决android BitmapFactory.decodeStream()返回null
- BitmapFactory.decodeStream方法返回null的错误分析
- (Bitmap OOM) BitmapFactory.nativeDecodeStream
- BitmapFactory.decodeStream()与BitmapFactory.decodeResource()
- Android 压缩网络上的图片BitmapFactory.decodeStream()返回为空的问题
- Bitmap的生成流程之BitmapFactory.decodeResource VS BitmapFactory.decodeStream
- BitmapFactory.decodeStream方法OutOfMemoryError 解决方法
- 关于BitmapFactory.decodeStream(is)方法无法正常解码为Bitmap对象的解决方法