~~~ public static final int PHOTOZOOM = 0; // 相册/拍照 public static final int PHOTOTAKE = 1; // 相册/拍照 public static final int IMAGE_COMPLETE = 2; // 结果 public static final int CROPREQCODE = 3; // 截取 private String photoSavePath;// 保存路径 private String photoSaveName;// 图pian名 private String path;// 图片全路径 private String SavePath; ~~~ 1.相册,拍照的PopupWindow调出 ~~~ private void showPopupWindow(View parent) { if (popWindow == null) { View view = layoutInflater.inflate(R.layout.pop_select_photo, null); popWindow = new PopupWindow(view, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, true); initPop(view); } popWindow.setAnimationStyle(android.R.style.Animation_InputMethod); popWindow.setFocusable(true); popWindow.setOutsideTouchable(true); StrFormat.fitPopupWindowOverStatusBar(popWindow, true); popWindow.setBackgroundDrawable(new BitmapDrawable()); popWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); popWindow.showAtLocation(parent, Gravity.CENTER, 0, 0); } public void initPop(View view) { photograph = (TextView) view.findViewById(R.id.photograph);// 拍照 albums = (TextView) view.findViewById(R.id.albums);// 相册 cancel = (LinearLayout) view.findViewById(R.id.cancel);// 取消 photograph.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { popWindow.dismiss(); photoSaveName = String.valueOf(System.currentTimeMillis()) + ".png"; Uri imageUri = null; Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); imageUri = Uri.fromFile(new File(photoSavePath, photoSaveName)); openCameraIntent.putExtra(MediaStore.Images.Media.ORIENTATION, 0); openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); Log.e("path", "" + imageUri); startActivityForResult(openCameraIntent, PHOTOTAKE); } }); albums.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { popWindow.dismiss(); Intent openAlbumIntent = new Intent(Intent.ACTION_GET_CONTENT); openAlbumIntent.setDataAndType( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); startActivityForResult(openAlbumIntent, PHOTOZOOM); } }); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { popWindow.dismiss(); } }); } ~~~ 2.图片选择及拍照结果 ~~~ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != RESULT_OK) { return; } Uri uri = null; switch (requestCode) { case PHOTOZOOM:// 相册 uri = data.getData(); path = StrFormat.getRealFilePath(UserInformation.this, uri); Intent intent3 = new Intent(UserInformation.this, ImageClip.class); intent3.putExtra("path", path); startActivityForResult(intent3, IMAGE_COMPLETE); break; case PHOTOTAKE:// 拍照 path = photoSavePath + photoSaveName; uri = Uri.fromFile(new File(path)); Intent intent2 = new Intent(UserInformation.this, ImageClip.class); intent2.putExtra("path", path); startActivityForResult(intent2, IMAGE_COMPLETE); break; case IMAGE_COMPLETE: SavePath = data.getStringExtra("path"); Glide.with(this).load(SavePath).placeholder(R.drawable.erha) .transform(new CircleTransform(this)).into(imgUserImage); break; default: break; } super.onActivityResult(requestCode, resultCode, data); } ~~~