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到TH BitmapFactory:
Bitmap bitmap = BitmapFactory.decodeStream(new BufferedInputStream(inputStream));
这两个解决方案应该做到这一点。
更多信息可以在错误报告的意见中找到:android bug no.6066
你能提供一个链接到一个图像,表现出这种行为? – CommonsWare 2010-05-07 11:26:15
不幸的是,我不能。我明白你在这里间接暗示...... :) – Samuh 2010-05-08 04:45:07