首页 > 代码库 > 保存view到本地图片
保存view到本地图片
1. 保存到自定义路径
Calendar name = Calendar.getInstance(); String path = "/sdcard/lef/"; if (Environment.getExternalStorageDirectory() != null) { File file = new File(path); if (!file.exists()) file.mkdirs(); dv.setDrawingCacheEnabled(true); Bitmap a = Bitmap.createBitmap(dv.getDrawingCache()); dv.setDrawingCacheEnabled(false); FileOutputStream fo = new FileOutputStream(file.getPath() + "/" + name.getTimeInMillis() + ".png"); a.compress(Bitmap.CompressFormat.PNG, 100, fo); fo.flush(); fo.close(); } sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageState() + path))); Toast.makeText(HandDraw.this, "图片保存成功", Toast.LENGTH_SHORT) .show(); 2.保存到系统相册 ContentResolver cr = HandDraw.this.getContentResolver(); String path = MediaStore.Images.Media.insertImage(cr ,Bitmap.createBitmap(dv.cacheBitmap), "", ""); sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory()+ path)));
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。