android – Skia Decoder无法解码远程Stream

我正在尝试打开JPEG图像的远程Stream并将其转换为Bitmap对象:
BitmapFactory.decodeStream(
new URL("http://some.url.to/source/image.jpg")
.openStream());

解码器返回null,在日志中我得到以下消息:

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

注意:
1.内容长度不为零,内容类型为image / jpeg
2.当我在浏览器中打开URL时,我可以看到图像.

在这里失踪的是什么?

请帮忙.谢谢.

解决方法

android bug n°6066中提供的解决方包括重写std FilterInputStream,然后将其发送到BitmapFactory.
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 byteValue = read();
                  if (byteValue < 0) {
                      break;  // we reached EOF
                  } else {
                      bytesSkipped = 1; // we read one byte
                  }
           }
           totalBytesSkipped += bytesSkipped;
        }
        return totalBytesSkipped;
    }
}

然后使用decodeStream函数

Bitmap bitmap = BitmapFactory.decodeStream(new FlushedInputStream(inputStream));

我发现的另一个解决方案是简单地给BitmapFactory一个BufferedInputStream:

Bitmap bitmap = BitmapFactory.decodeStream(new BufferedInputStream(inputStream));

这两种解决方案应该可行.

更多信息可以在错误报告评论中找到:android bug no.6066

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...