保存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)));


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章