保存图片到手机内存

 1 方法一:
2 public void saveFile(Bitmap bm, String fileName)
3 throws IOException {
4 File dirFile = new File(ALBUM_PATH);
5 if (!dirFile.exists()) {
6 dirFile.mkdir();
7 }
8 File myCaptureFile = new File(ALBUM_PATH + fileName);
9 BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
10 bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);
11 bos.flush();
12 bos.close();
13 }
14
15 方法二:
16 ////////
17 public void saveMyBitmap(String bitName, Bitmap mBitmap) throws IOException {
18 File f = new File("/sdcard/" + bitName + ".png");
19 f.createNewFile();
20 FileOutputStream fOut = null;
21 try {
22 fOut = new FileOutputStream(f);
23 } catch (FileNotFoundException e) {
24 e.printStackTrace();
25 }
26 mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
27 try {
28 fOut.flush();
29 } catch (IOException e) {
30 e.printStackTrace();
31 }
32 try {
33 fOut.close();
34 } catch (IOException e) {
35 e.printStackTrace();
36 }
37 }
posted @ 2012-02-18 19:47  灰太狼_lilongmin  阅读(340)  评论(0编辑  收藏  举报