如何转换的OutputStream到文件? [英] How to convert OutputStream to File?

查看:4593
本文介绍了如何转换的OutputStream到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在code以下得到的图像从某个位置 - ,使这一形象融为一体preSS图像。 但我需要做的COM preSS图像以文件...我怎样才能做到这一点?

 文件COM pressFile = NULL;
   档案文件=新的文件(MyFile的);
   的OutputStream FOUT =新的FileOutputStream(文件);
   如果(image.com preSS(Bitmap.Com pressFormat.PNG,100,FOUT))
   {
       fOut.flush();
       fOut.close();

      COM pressFile = ??? //我需要在这里做的OutputStream要回档案。
   }
 

解决方案

image.com preSS 已写入映像文件,假设你能得到正确的文件名。 因此,使用这样的:

 档案文件=新的文件(Environment.getExternalStorageDirectory()+/myimage.png);
   FileOutputStream中FOUT =新的FileOutputStream(文件);
   image.com preSS(Bitmap.Com pressFormat.PNG,100,FOUT);
   fOut.close();
 

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 ?

   File compressFile = null;
   File file = new File("MyFile");
   OutputStream fOut    = new FileOutputStream(file);
   if(image.compress(Bitmap.CompressFormat.PNG, 100, fOut))
   {
       fOut.flush();
       fOut.close();

      compressFile = ??? // I need here to make the OutputStream  to be back to file. 
   }

解决方案

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();

这篇关于如何转换的OutputStream到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆