头像上传为最常见的功能之一,流程包括拍照/打开相册 裁剪 上传 下边介绍头像上传的整个流程。
CSDN该节视频连接 http://edu.csdn.net/course/detail/2741/53099
- 拍照 打开系统照相机
//定义图片存储的位置
file = new File(Environment.getExternalStorageDirectory(),
System.currentTimeMillis() + ".png");
// 隐式意图打开系统界面 --要求回传
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// 存到什么位置
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, OPEN_CAMERA);
- 打开相册
// 打开相册
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, OPEN_GALLERY);
- 裁剪