bitmap保存到本地图片的方法

/**
 * 保存bitmap到本地
 *
 * @param bitmap Bitmap
 */
public static void saveBitmap(Bitmap bitmap,String path) {
    String savePath;
    File filePic;
    if (Environment.getExternalStorageState().equals(
        Environment.MEDIA_MOUNTED)) {
        savePath = path;
    } else {
        Log.e("tag", "saveBitmap failure : sdcard not mounted");
        return;
    }
    try {
        filePic = new File(savePath);
        if (!filePic.exists()) {
            filePic.getParentFile().mkdirs();
            filePic.createNewFile();
        }
        FileOutputStream fos = new FileOutputStream(filePic);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
    } catch (IOException e) {
        Log.e("tag", "saveBitmap: " + e.getMessage());
        return;
    }
    Log.i("tag", "saveBitmap success: " + filePic.getAbsolutePath());
}
    原文作者:飞行的鲤鱼
    原文地址: https://blog.csdn.net/crrose/article/details/82889330
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞