安卓学习-其他-保存图片

    /** 保存方法 */
    public void saveBitmap(Bitmap bm, String picName) {
        //获取SD卡的目录,不建议直接写sdcard
        File f = new File(Environment.getExternalStorageDirectory().getPath(),picName);
        //若存在,则删除
        if (f.exists()) {
            f.delete();
        }
        try {
            FileOutputStream out = new FileOutputStream(f);
            bm.compress(Bitmap.CompressFormat.PNG, 90, out);
            out.flush();
            out.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

 

posted on 2014-08-06 15:14  weijj  阅读(128)  评论(0编辑  收藏  举报

导航