代码之家  ›  专栏  ›  技术社区  ›  Samuh

Skia解码器无法解码远程流

  •  7
  • Samuh  · 技术社区  · 15 年前

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

        BitmapFactory.decodeStream(
    new URL("http://some.url.to/source/image.jpg")
    .openStream());
    

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

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

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

    我在这里找不到什么?

    请帮忙。谢谢。

    4 回复  |  直到 7 年前
        1
  •  10
  •   Marek Sebera    13 年前

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

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

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

    这两个解决方案应该会起作用。

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

        2
  •  3
  •   Samuh    15 年前

    似乎流和安卓处理它的方式有问题;这里面的补丁 bug report 暂时解决了这个问题。

        3
  •  0
  •   lucasddaniel    11 年前

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

        4
  •  0
  •   JanKnotek    7 年前

    我找到了一个库,可以打开安卓Skia失败的图片。它可以用于某些用例:

    https://github.com/suckgamony/RapidDecoder

    对我来说,它解决了这个问题,因为我没有一次加载许多图像,而且我加载的许多图像都有ICC配置文件。 我还没有尝试将它与一些常见的图书馆(如毕加索图书馆或格莱德图书馆)结合起来。