How to convert OutputStream to File?

后端 未结 2 648
轮回少年
轮回少年 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:28

    image.compress already writes the image to the file, assuming you gave a correct file name. So use it like this:

       File file = new File(Environment.getExternalStorageDirectory() + "/myimage.png");
       FileOutputStream fOut = new FileOutputStream(file);
       image.compress(Bitmap.CompressFormat.PNG, 100, fOut);
       fOut.close();
    

提交回复
热议问题