把bitmap转成文件存入APP项目目录

时间:2020-12-09 11:50:35   收藏:0   阅读:7

   app卸载之后文件消失;或者存在项目BCache区,当手机空间不足都有可能被删除。

 //把bitmap转成file
    public File getFile(Bitmap bitmap) {

        File file = new File(getFilesDir(), "payCode.png");

        try {
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
            bos.flush();
            bos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return file;
    }

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!