首页 > 代码库 > 保存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)));