使用下面的代碼,我在imageBitmap = BitmapFactory.decodeStream(is2,null, options);
處獲取異常 NULL。
先前運行時,可以解碼,但是現在為什麼不行了呢?decodeStream 拋出 null嗎?
public void showImageThumb(FileInputStream is)
{
final int IMAGE_MAX_SIZE = 100;
FileInputStream is2 = is;
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap imageBitmap = BitmapFactory.decodeStream(is,null, options);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int height = options.outHeight;
int width = options.outWidth;
int scale = 1;
if ( height > IMAGE_MAX_SIZE || width > IMAGE_MAX_SIZE)
{
scale = (int)Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(options.outHeight, options.outWidth)) / Math.log(0.5)));
}
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
options = new BitmapFactory.Options();
options.inSampleSize = scale*2;
imageBitmap = BitmapFactory.decodeStream(is2,null, options);
height = options.outHeight;
width = options.outWidth;
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); //ERROR HERE
imageSelectedThumb = baos.toByteArray();
版本2.2以下bug,是會出現概率性的解析失敗的異常
參考解決方案:
http://blog.csdn.net/catoop/article/details/8470031