test image here: http://images.plurk.com/tn_4134189_bf54fe8e270ce41240d534b5133884ee.gif
I've tried several solutions found on the internet but there is no working solution.
I'm using the following snippet code:
Url imageUrl = new Url("http://images.plurk.com/tn_4134189_bf54fe8e270ce41240d534b5133884ee.gif");
Bitmap image = BitmapFactory.decodeStream(imageUrl.openStream());
Always getting this log:
DEBUG/skia(1441): --- decoder->decode returned false
Any help? Thanks.
EDIT:
Those images failed to be decoded are also can not be shown on a WebView
. But can see if open in a Browser.
I had the same problem, partially was fixed by this class:
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 byte = read();
if (byte < 0) {
break; // we reached EOF
} else {
bytesSkipped = 1; // we read one byte
}
}
totalBytesSkipped += bytesSkipped;
}
return totalBytesSkipped;
}
}
And:
InputStream in = null;
try {
in = new java.net.URL(imageUrl).openStream();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Bitmap image = BitmapFactory.decodeStream(new FlushedInputStream(in));
It helped in most cases, but this is not universal solution. For more refer to this bugreport.
Best luck!