android 关于截屏保存图片到相册功能

iv_photo.buildDrawingCache();
iv_photo.setBackgroundColor(mContext.getResources().getColor(R.color.TextColorWhite));
iv_photo.setDrawingCacheEnabled(true);
Bitmap bitmap = iv_photo.getDrawingCache();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
String str = formatter.format(curDate);

MediaStore.Images.Media.insertImage(mContext.getContentResolver(), bitmap, str, "");
UpdateUserPhotoActivity.this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
iv_photo.setBackgroundColor(mContext.getResources().getColor(R.color.black));
Toast.makeText(mContext,"保存相册成功!",Toast.LENGTH_SHORT).show();

posted @ 2015-04-28 13:58  点兵  阅读(452)  评论(0)    收藏  举报