ssummeraw 2013-05-30 01:40 采纳率: 10%
浏览 2688
已采纳

当在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 2013-05-30 01:52
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键