save bitmap to file

public void saveBitmap(Bitmap bm, String path) {
        String dir = path.substring(0,path.lastIndexOf("/"));
        File dirFile =  new File(dir);
        if (!dirFile.exists()) {
            dirFile.mkdirs ();
        }
        File f = new File(path);
        if (f.exists()) {
            f.delete();
        }
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(f);
            bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
        } catch (FileNotFoundException e) {
            e.printStackTrace ();
        } finally {
            if (out != null) {
                try {
                    out.flush();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace ();
                }
            }
        }
    }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326401274&siteId=291194637