保存图片到sd卡指定的(创建)文件夹

sd卡读写权限:
    
    
public class SaveImage {
    private final static String CACHE_PATH = "/(新建的文件夹目录名称)";
    public static void save(String inputText) {
        Bitmap bm = Bitmap.createBitmap(400, 200, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bm);
        Paint paint = new Paint();
        canvas.save(Canvas.ALL_SAVE_FLAG );
        canvas.restore();

        File f = new File(Environment.getExternalStorageDirectory().getPath() + CACHE_PATH);
        //建立文件夹
        f.mkdirs();
        FileOutputStream fos;
        try {
            fos = new FileOutputStream(f + "/" + "image.png");
            bm.compress(Bitmap.CompressFormat.PNG, 50, fos);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

}
 
  

你可能感兴趣的:(保存图片到sd卡指定的(创建)文件夹)