//保存bitmap到指定文件。

    public static void saveBitmap(Bitmap bmp, String targetPath) {

        File file = new File(targetPath);
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {
            saveBitmap(bmp, new FileOutputStream(file));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    private static void saveBitmap(Bitmap bmp, FileOutputStream fos) {
        try {
            //80 is the compress quality
            bmp.compress(Bitmap.CompressFormat.JPEG, 80, fos);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.flush();
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

更多相关文章

  1. android的文件操作
  2. 更新android sdk出现 A folder failed to be renamed or moved
  3. Android(安卓)下实现带有图标和Checkbox的 ListView Item(2)
  4. 向SD卡写文件
  5. Android(安卓)Studio多环境打包
  6. [Android]解决failed to get the required ADT version from sdk
  7. Android简单文件浏览器源代码
  8. anroid 7.1添加自定义api服务
  9. NPM 和webpack 的基础使用

随机推荐

  1. Storyboard的爱与恨
  2. [AS3.6.1]Kotlin学习笔记3
  3. 520,亲爱的自己
  4. [置顶] Android---菜单详解
  5. android传感器实现摇一摇功能
  6. Android(安卓)软键盘不能弹出
  7. Android类参考---HandlerThread
  8. android processBar seekBar 定制(底部间
  9. 关于Android的字体
  10. Android(安卓)两个Fragment之间传递数据