ream总是返回null和Skia的德codeR显示德code返

ream总是返回null和Skia的德codeR显示德code返

本文介绍了BitmapFactory.de codeStream总是返回null和Skia的德codeR显示德code返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

测试图像在这里: http://images.plurk.com/tn_4134189_bf54fe8e270ce41240d534b5133884ee.gif

我试着在互联网上发现了几个解决方案,但目前还没有可行的解决方案。

I've tried several solutions found on the internet but there is no working solution.

我用下面的代码片段code:

I'm using the following snippet code:

Url imageUrl = new Url("http://images.plurk.com/tn_4134189_bf54fe8e270ce41240d534b5133884ee.gif");
Bitmap image = BitmapFactory.decodeStream(imageUrl.openStream());

始终得到这个日志:

Always getting this log:

DEBUG/skia(1441): --- decoder->decode returned false

任何帮助吗?谢谢你。

Any help?Thanks.

编辑:

这些图像没有被取消codeD也不能在的WebView 显示。如果开放,但可以看到一个浏览器。

Those images failed to be decoded are also can not be shown on a WebView. But can see if open in a Browser.

推荐答案

试试这个作为临时解决方法:

Try this as a temporary workaround:

首先添加下面的类:

  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包住原始数据流:

Then wrap your original stream with PlurkInputStream:

Bitmap bitmap = BitmapFactory.decodeStream(new PlurkInputStream(originalInputStream));

让我知道,如果这可以帮助你。

Let me know if this helps you.

编辑:

对不起,请尝试以下版本而不是:

Sorry please try the following version instead:

        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;
                }
            }
        }

请注意,这不是有效的code,也没有这是一个充满/正确的解决方案。它适用于大多数的情况下,但不是全部。

Note that this is not efficient code nor is this a full/correct solution. It will work for most cases, but not all.

这篇关于BitmapFactory.de codeStream总是返回null和Skia的德codeR显示德code返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 15:30