Take the 2-minute tour ×

I am trying to open a remote Stream of a JPEG image and convert it into a Bitmap object:

new URL("http://some.url.to/source/image.jpg")

The decoder returns null and in the logs I get the following message:

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

1. the content length is non-zero and content type is image/jpeg
2. When I open the URL in browser I can see the image.

What is that I am missing here?

Please help. Thanks.

share|improve this question
Can you provide a link to an image that exhibits this behavior? –  CommonsWare May 7 '10 at 11:26
Unfortunately, i cant. I understand what you are indirectly hinting to here... :) –  Samuh May 8 '10 at 4:45
add comment

3 Answers

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

static class FlushedInputStream extends FilterInputStream {
    public FlushedInputStream(InputStream inputStream) {

    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;

and then use the decodeStream function:

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

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

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

These two solutions should do the trick.

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

share|improve this answer
FWIW the FlushedInputStream method worked for me; the BufferedInputStream did not. Also, "byte" is a reserved keyword, so you should change "int byte" to "int byteValue" or something. –  esilver Oct 28 '11 at 5:48
This solution works for me and I think this should be the correct answer. –  KaHeL Jul 26 '12 at 3:43
This bug is still not fixed and the workarounds don't always work. –  slybloty Oct 25 '12 at 14:14
add comment
up vote 3 down vote accepted

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer


