我正在尝试打开JPEG图像的远程流,并将其转换为位图对象:

    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时,我可以看到图像。

我在这里缺少什么?

请帮忙。谢谢。

有帮助吗?

解决方案 2

似乎有一些问题的流以及Android处理的方式;这个补丁 错误报告 现在解决了问题。

其他提示

提供的解决方案 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;
    }
}

然后使用解码函数:

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

我发现的另一个解决方案是简单地将BufferedInputStream提供给bitmapfactory:

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

这两种解决方案应该解决问题。

更多信息可以在错误报告注释中找到: Android Bug No.6066

对我来说,问题是图像的颜色类型:您的图像是颜色= Cymk不在RGB中

我找到了一个库,可以打开Android Skia失败的图像。它对于某些用户酶很有用:

https://github.com/suckgamony/rapiddecoder

对我来说,它解决了问题,因为我没有一次加载许多图像,并且我加载的大量图像具有ICC配置文件。我没有尝试将其与毕加索或滑行等一些常见库集成。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top