关于okhttp的response.body().byteStream()不能作为 BitmapFactory.decodeStream()参数的疑惑

当把okhttp的response.body().byteStream()作为 BitmapFactory.decodeStream()的inputStream时,bitmap 一直返回null,代码如下:
public void onResponse(final Response response) throws IOException {
       InputStream inputStream= response.body().byteStream();
      bitmap=BitmapFactory.decodeStream(inputStream);


但如果先把 response.body().byteStream()用ByteArrayOutputStream存下来,然后再作为BitmapFactory.decodeByteArray()的参数,bitmap的decode又是正常的,代码如下:
public void onResponse(final Response response) throws IOException {
       InputStream inputStream= response.body().byteStream();
       ByteArrayOutputStream outStream = new ByteArrayOutputStream();
       byte[] buffer = new byte[1024];
       byte[] bmp_buffer;
       int len = 0;
        while( (len=inputStream.read(buffer)) != -1){
                    outStream.write(buffer, 0, len);
         }
        outStream.close();
        inputStream.close();
        bmp_buffer=outStream.toByteArray();
       bitmap = BitmapFactory.decodeByteArray(bmp_buffer, 0, bmp_buffer.length);

难道okhttp的byteStream()不能直接作为BitmapFactory.decodeStream()的inputStream?如果是,为什么?谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值