Skip to content Skip to sidebar Skip to footer

Skia Decoder Fails To Decode Remote Stream

I am trying to open a remote Stream of a JPEG image and convert it into a Bitmap object: BitmapFactory.decodeStream( new URL('http://some.url.to/source/image.jpg') .openStrea

Solution 1:

The solution provided in android bug n°6066 consist in overriding the std FilterInputStream and then send it to the BitmapFactory.

staticclassFlushedInputStreamextendsFilterInputStream {
    publicFlushedInputStream(InputStream inputStream) {
    super(inputStream);
    }

    @Overridepubliclongskip(long n)throws IOException {
        longtotalBytesSkipped=0L;
        while (totalBytesSkipped < n) {
            longbytesSkipped= in.skip(n - totalBytesSkipped);
            if (bytesSkipped == 0L) {
                  intbyteValue= read();
                  if (byteValue < 0) {
                      break;  // we reached EOF
                  } else {
                      bytesSkipped = 1; // we read one byte
                  }
           }
           totalBytesSkipped += bytesSkipped;
        }
        return totalBytesSkipped;
    }
}

and then use the decodeStream function:

Bitmapbitmap= BitmapFactory.decodeStream(newFlushedInputStream(inputStream));

The other solution i've found is to simply give a BufferedInputStream to th BitmapFactory:

Bitmapbitmap= BitmapFactory.decodeStream(newBufferedInputStream(inputStream));

These two solutions should do the trick.

More information can be found in the bug report comments : android bug no.6066

Solution 2:

seems there was some problem with the stream and the way android handled it; the patch in this bug report solved the problem for now.

Solution 3:

For me the problem is with type of color of image: your image are in color= CYMK not in RGB

Solution 4:

I have found a library, which can open images on which Android SKIA fails. It can be useful for certain usecases:

https://github.com/suckgamony/RapidDecoder

For me it solved the problem as I am not loading many images at once and lot of images I load have ICC profile. I haven't tried integrating it with some common libraries like Picasso or Glide.

Post a Comment for "Skia Decoder Fails To Decode Remote Stream"