Bitmap类有一compress成员,可以把bitmap保存到一个stream中。
- public void saveMyBitmap(String bitName) throws IOException {
- File f = new File("/sdcard/Note/" + bitName + ".png");
- f.createNewFile();
- FileOutputStream fOut = null;
- try {
- fOut = new FileOutputStream(f);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
- try {
- fOut.flush();
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- fOut.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }