Guest User

Untitled

a guest
Mar 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  2.  
  3. File pics = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
  4. File cameraPhotoFile = new File(pics, System.currentTimeMillis()+".jpg");
  5.  
  6. if (takePicture.resolveActivity(getActivity().getPackageManager()) != null) {
  7. takePicture.putExtra(MediaStore.EXTRA_OUTPUT, cameraPhotoFile);
  8. startActivityForResult(takePicture, REQUEST_CAMERA);
  9. }
  10.  
  11. if (resultCode == RESULT_OK && requestCode ==REQUEST_CAMERA) {
  12. uri = data.getData();
  13. performCrop();
  14.  
  15. private void performCrop() {
  16. // take care of exceptions
  17. try {
  18. // call the standard crop action intent (the user device may not
  19. // support it)
  20. Intent cropIntent = new Intent("com.android.camera.action.CROP");
  21. // indicate image type and Uri
  22. cropIntent.setDataAndType(uri, "image/*");
  23. // set crop properties
  24. cropIntent.putExtra("crop", "true");
  25. // indicate aspect of desired crop
  26. cropIntent.putExtra("aspectX", 1);
  27. cropIntent.putExtra("aspectY", 1);
  28. // indicate output X and Y
  29. cropIntent.putExtra("outputX", 128);
  30. cropIntent.putExtra("outputY", 128);
  31. cropIntent.putExtra("scale", true);
  32. // retrieve data on return
  33. cropIntent.putExtra("return-data", true);
  34. // start the activity - we handle returning in onActivityResult
  35. startActivityForResult(cropIntent, CROP_PIC);
  36. }
  37.  
  38. else if (requestCode == CROP_PIC) {
  39.  
  40. // try{
  41. Bundle extras = data.getExtras();
  42. // get the cropped bitmap
  43. if (extras != null) {
Add Comment
Please, Sign In to add comment