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 を BitmapFactory に与えることです:
Bitmap bitmap = BitmapFactory.decodeStream(new BufferedInputStream(inputStream));
これらの 2 つのソリューションでうまくいくはずです。
詳細については、バグ レポートのコメントを参照してください: Android バグ番号 6066