2 ssummeraw ssummeraw 于 2013.05.30 09:40 提问

当在bitmap 中存储时DecodeStream抛出空值

使用下面的代码,我在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();

1个回答

franzhong
franzhong   2013.05.30 09:52
已采纳

版本2.2以下bug,是会出现概率性的解析失败的异常
参考解决方案:
http://blog.csdn.net/catoop/article/details/8470031

Csdn user default icon
上传中...
上传图片
插入图片