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

   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;
    }

 

posted @ 2020-12-04 16:25  风肖肖(肖遥)  阅读(289)  评论(0编辑  收藏  举报