且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android的德codeR->德code返回false的位图下载

更新时间:2023-12-02 15:52:58

有一个在FlushedInputStream(是)一个错误。它失败的连接速度慢,但你可以试试我的神奇code,以解决它。

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.