android 保存bitmap到本地

来源:互联网 发布:淘宝客服兼职日结工资 编辑:程序博客网 时间:2024/06/05 06:02
//3.保存Bitmap        try {            File path = new File(SavePath);            //文件            final String filepath = SavePath + System.currentTimeMillis() + ".png";            final File file = new File(filepath);            if (!path.exists()) {                path.mkdirs();            }            if (!file.exists()) {                file.createNewFile();            }            FileOutputStream fos = null;            fos = new FileOutputStream(file);            if (null != fos) {                bmp.compress(Bitmap.CompressFormat.PNG, 0, fos);                fos.flush();                fos.close();

bmp.compress(Bitmap.CompressFormat.PNG, 0, fos);可以设置对原图片进行比例压缩然后保存到本地。在此方法中,已将图片流写入fos。接下来只需刷新一下输出流就可以了。