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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退