How to convert OutputStream to File?

后端 未结 2 650
轮回少年
轮回少年 2021-01-26 00:52

The code below get image from some location - and make this image compress image. But i need to make the compress Image to be File ... How can i do it ?

   Fil         


        
2条回答
  •  故里飘歌
    2021-01-26 01:32

    As stated in the documentation for OutputStream:

    Most clients will use output streams that write data to the file system (FileOutputStream), the network (getOutputStream()/getOutputStream()), or to an in-memory byte array (ByteArrayOutputStream).

    Meaning the data sent to the OutputStream has allready been written to your file.

    If what you mean is that you need access to the file once it has been compressed you should look at documentation for the compress() method which states:

    If this returns true, the bitmap can be reconstructed by passing a corresponding inputstream to BitmapFactory.decodeStream().

    So what you need to do is this:

    image = BitmapFactory.decodeStream( new FileInputStream( file ) );
    

提交回复
热议问题