当前位置: 代码迷 >> Android >> Android decoder->decode returned false for Bit地图 download
  详细解决方案

Android decoder->decode returned false for Bit地图 download

热度:261   发布时间:2016-05-01 17:21:26.0
Android decoder->decode returned false for Bitmap download

There is a bug in FlushedInputStream(is). it fails on slow connections but you can try my magical code to fix it.

Bitmap b = BitmapFactory.decodeStream(new FlushedInputStream(is));imageView.setImageBitmap(b);

create a static class outside your method

?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 b = read();? ? ? ? ? ? ? ? ? ? if (b < 0) {? ? ? ? ? ? ? ? ? ? ? ? break; ?// we reached EOF? ? ? ? ? ? ? ? ? ? } else {? ? ? ? ? ? ? ? ? ? ? ? bytesSkipped = 1; // we read one byte? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? totalBytesSkipped += bytesSkipped;? ? ? ? ? ? }? ? ? ? ? ? return totalBytesSkipped;? ? ? ? }? ? }

and here you go.. now you will not have any problem.

  相关解决方案