有可能是jpeg吗?
请参阅此已知问题:-
https://code.google.com/p/android/issues/detail?id=6066
我使用以下解码位图:-
BitmapFactory.decodeStream(new FlushedInputStream(is), null, opts);
public 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 myByte = read();
if (myByte < 0) {
break; // we reached EOF
} else {
bytesSkipped = 1; // we read one byte
}
}
totalBytesSkipped += bytesSkipped;
}
return totalBytesSkipped;
}
}
此外,如果某些图像很大,您可能需要设置样本大小,以免导致分配过大。
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = sampleSize;
其中 sampleSize 是您计算的合理值。