android - BitmapFactory.decodeStream 总是返回 null 并且 skia 解码器显示解码返回 false

标签 android image bitmap skia

测试图片在这里: 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/

相关文章:

android - Intent 的 OnDestroy()

android - android中是否有用于识别语音相同声音的库

python - 使用 plotly offline 将图形生成为图像

android TouchImageView 高度不改变

android - 在位图图像中查找多边形

java - int argb color 输出奇怪的值

android - 将Android SDK从29降级到21

c# - .NET Core 2.2下System.Drawing中找不到Image类

angularjs - 使用 Angular JS 加载图像后更新 DIV 元素

java - MediaMetadata.getString java.lang.RuntimeException : Could not read bitmap from parcel blob