android 保存bitmap到本地

//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。接下來只需刷新一下輸出流就可以了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章