canvas 保存bitmap到本地

 File f = new File("/sdcard/DCIM/Camera/0.png");
                       FileOutputStream fos = null;
                       try {
                           fos = new FileOutputStream(f);
                           drawBitmap.compress(Bitmap.CompressFormat.PNG, 50, fos);
                       } catch (FileNotFoundException e) {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
                       }

 

<!-- 在SDCard中创建与删除文件权限 -->     
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>     
<!-- 往SDCard写入数据权限 -->     
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

参考:http://wuxiaolong.me/2015/04/23/CanvasToPhoto/

posted @ 2018-04-28 10:19  牧马人夏峥  阅读(757)  评论(0编辑  收藏  举报