Bitmapfactory.decodestream(inputstream) Always Return Null When Some Bytes Are Wrong
I'm building an android app and I'm currently having trouble retrieving a bitmap from an URL. Here is the code I'm using : public static Bitmap bmpFromURL(URL imageURL){ Bitma
Solution 1:
This is a known bug fixed in a future version of Android. You can work around it by first copying the content of the InputStream into a byte[] array and then decoding the byte array itself.
Solution 2:
Try this one out..It worked for me. hope it helps.
result = BitmapFactory.decodeStream(newPatchInputStream(input));
publicclassPatchInputStreamextendsFilterInputStream {
publicPatchInputStream(InputStream input) {
super(input);
}
publiclongskip(long n)throws IOException {
longm=0L;
while (m < n) {
long_m= in.skip(n-m);
if (_m == 0L) break;
m += _m;
}
return m;
}
}
Post a Comment for "Bitmapfactory.decodestream(inputstream) Always Return Null When Some Bytes Are Wrong"