//保存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利用TTF文件设置字体
  2. 向SD卡写文件
  3. android html 读写文件
  4. Android 播放MP4文件
  5. 【Android】如何实现一个简单的文件浏览器
  6. Android文件权限(Linux的权限)
  7. Android和IOS录制mp3语音文件的方法

随机推荐

  1. 实现TextView的垂直滚动以及通过代码设置
  2. Android中的ABI
  3. android发送短信验证码并自动获取验证码
  4. Android 浅谈Socket
  5. Android(安卓)glide-transformations 使
  6. android canvas d
  7. svn在linux下的使用(svn命令行)
  8. [Android]百度地图之几何标注和文字覆盖
  9. Android Activity生命周期及详解
  10. 事件分发系列—View中的dispatchTouchEve