测试图片在这里: http://images.plurk.com/tn_4134189_bf54fe8e270ce41240d534b5133884ee.gif
我已经尝试了在 Internet 上找到的几种解决方案,但没有有效的解决方案。
我正在使用以下代码 fragment :
Url imageUrl = new Url("http://images.plurk.com/tn_4134189_bf54fe8e270ce41240d534b5133884ee.gif");
Bitmap image = BitmapFactory.decodeStream(imageUrl.openStream());
总是得到这个日志:
DEBUG/skia(1441): --- decoder->decode returned false
有什么帮助吗? 谢谢。
编辑:
那些解码失败的图像也不能在WebView
上显示。但是可以看到是否在浏览器中打开。
最佳答案
尝试将此作为临时解决方法:
首先添加如下类:
public static class PlurkInputStream extends FilterInputStream {
protected PlurkInputStream(InputStream in) {
super(in);
}
@Override
public int read(byte[] buffer, int offset, int count)
throws IOException {
int ret = super.read(buffer, offset, count);
for ( int i = 2; i < buffer.length; i++ ) {
if ( buffer[i - 2] == 0x2c && buffer[i - 1] == 0x05
&& buffer[i] == 0 ) {
buffer[i - 1] = 0;
}
}
return ret;
}
}
然后使用 PlurkInputStream 包装您的原始流:
Bitmap bitmap = BitmapFactory.decodeStream(new PlurkInputStream(originalInputStream));
如果这对您有帮助,请告诉我。
编辑:
抱歉,请尝试以下版本:
for ( int i = 6; i < buffer.length - 4; i++ ) {
if ( buffer[i] == 0x2c ) {
if ( buffer[i + 2] == 0 && buffer[i + 1] > 0
&& buffer[i + 1] <= 48 ) {
buffer[i + 1] = 0;
}
if ( buffer[i + 4] == 0 && buffer[i + 3] > 0
&& buffer[i + 3] <= 48 ) {
buffer[i + 3] = 0;
}
}
}
请注意,这不是有效的代码,也不是完整/正确的解决方案。它适用于大多数情况,但不是全部。
关于android - BitmapFactory.decodeStream 总是返回 null 并且 skia 解码器显示解码返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3802820/