把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;
    }
以前的是程序员的老板,现在是末路出家的程序员小白。
原文地址:https://www.cnblogs.com/xiaoyao-blog/p/14086480.html