保存图片到SD卡

添加SD卡写权限

方法

public void saveMyBitmap(String bitName, Bitmap mBitmap) {
    File f = new File("/sdcard/" + bitName + ".png");
    try {
        f.createNewFile();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        DebugMessage.put("在保存图片时出错:" + e.toString());
    }
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(f);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
    try {
        fOut.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        fOut.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

posted on 2015-08-18 23:39  封起De日子  阅读(115)  评论(0编辑  收藏  举报

导航