BitmapFactory.decodeStream 总是返回 null 并且skia 解码器显示解码返回false [英] BitmapFactory.decodeStream always returns null and skia decoder shows decode returned false

查看:29
本文介绍了BitmapFactory.decodeStream 总是返回 null 并且skia 解码器显示解码返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我尝试了在互联网上找到的几种解决方案,但没有可行的解决方案.

我正在使用以下代码片段:

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

总是得到这个日志:

DEBUG/skia(1441): --- 解码器->解码返回假

有什么帮助吗?谢谢.

那些解码失败的图像也不能在WebView上显示.但是可以查看是否在浏览器中打开.

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

首先添加以下类:

 public static class PlurkInputStream extends FilterInputStream {受保护的 PlurkInputStream(InputStream in) {超级(在);}@覆盖public int read(byte[] buffer, int offset, int count)抛出 IOException {int ret = super.read(buffer, offset, count);for ( int i = 2; i < buffer.length; i++ ) {如果(缓冲区 [i - 2] == 0x2c && 缓冲区 [i - 1] == 0x05&&缓冲区[i] == 0 ) {缓冲区[i - 1] = 0;}}返回 ret;}}

然后用 PlurkInputStream 包装您的原始流:

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

如果这对您有帮助,请告诉我.

抱歉,请尝试以下版本:

 for ( int i = 6; i 

请注意,这不是高效的代码,也不是完整/正确的解决方案.它适用于大多数情况,但不是全部.

test image here: http://images.plurk.com/tn_4134189_bf54fe8e270ce41240d534b5133884ee.gif

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

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.

EDIT:

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:

First add the following class:

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

}

Then wrap your original stream with PlurkInputStream:

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

Let me know if this helps you.

EDIT:

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

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

这篇关于BitmapFactory.decodeStream 总是返回 null 并且skia 解码器显示解码返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆