Android解码器->解码位图下载返回false [英] Android decoder->decode returned false for Bitmap download
问题描述
我已经开始得到一个
DEBUG/skia(xxxx): --- decoder->decode returned false
关于我在 ImageViews 中使用的一些来自 Facebook 的个人资料图片的问题.大多数都可以完美运行,但偶尔我会发现一个永远无法运行的东西.
issue on a few profile images from Facebook that I use in ImageViews. Most work perfectly, but every once in a while I discover one that never works.
出于向后兼容性的原因,我正在针对 Android 1.6 编译我的应用程序.
I am compiling my application against Android 1.6 for backward compatibility reasons.
我进行了一些挖掘并发现了许多有关该问题的线索.我已经在使用这里讨论的 FlushedInputStream:http://code.google.com/p/android/issues/detail?id=6066
I did some digging and discovered a number of threads on the issue. I'm already using the FlushedInputStream discussed here: http://code.google.com/p/android/issues/detail?id=6066
Bitmap b = BitmapFactory.decodeStream(new FlushedInputStream(is));
imageView.setImageBitmap(b);
这是一个给我带来麻烦的例子:http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs269.snc3/23132_639284607_390_q.jpg
Here's an example that's causing me trouble: http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs269.snc3/23132_639284607_390_q.jpg
有人可以查看图像并帮助我找出导致问题的原因吗?
Can someone check out the image and help me figure out what's causing the trouble?
推荐答案
FlushedInputStream(is) 中存在一个错误.它在慢速连接时失败,但您可以尝试我的神奇代码来修复它.
There is a bug in FlushedInputStream(is). it fails on slow connections but you can try my magical code to fix it.
Bitmap b = BitmapFactory.decodeStream(new FlushedInputStream(is));
imageView.setImageBitmap(b);
在你的方法之外创建一个静态类
create a static class outside your 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 b = read();
if (b < 0) {
break; // we reached EOF
} else {
bytesSkipped = 1; // we read one byte
}
}
totalBytesSkipped += bytesSkipped;
}
return totalBytesSkipped;
}
}
你开始吧..现在你不会有任何问题了.
and here you go.. now you will not have any problem.
这篇关于Android解码器->解码位图下载返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!