Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. Intent crop = new Intent("com.android.camera.action.CROP");
  2. crop.setDataAndType(outputFileUri, "image/*");
  3.  
  4. crop.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  5. crop.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
  6.  
  7. crop.putExtra("crop", "true");
  8. crop.putExtra("aspectX", 139);
  9. crop.putExtra("aspectY", 185);
  10. crop.putExtra("scale", true);
  11.  
  12. crop.putExtra("return-data", true);
  13.  
  14. startActivityForResult(crop, CROP_AFTER_CAMERA);
  15.  
  16. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  17. super.onActivityResult(requestCode, resultCode, data);
  18. if (requestCode == PICK_FROM_CAMERA && resultCode == RESULT_OK) {
  19. if (outputFileUri != null) {
  20. crop_image();
  21. }
  22. }
  23.  
  24. else if (requestCode == EDIT_CROPPED_IMAGE) {
  25.  
  26. }
  27.  
  28. else if (requestCode == CROP_AFTER_CAMERA) {
  29.  
  30.  
  31. if (data != null) {
  32. Bundle bundle = data.getExtras();
  33. Bitmap cropBit = bundle.getParcelable("data");
  34.  
  35. imgView.setImageBitmap(cropBit);
  36.  
  37. saveBitmap(cropBit);
  38.  
  39. }
  40. }
  41.  
  42. else if (resultCode == RESULT_CANCELED) {
  43. Provider.deleteFile(getBaseContext(), outputFileUri);
  44. }
  45. }
  46.  
  47. OutputStream out = null;
  48.  
  49. File image_file = new File(targetFolder + filename);
  50.  
  51. try {
  52. image_file.createNewFile();
  53. out = new FileOutputStream(image_file);
  54.  
  55. bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
  56.  
  57. } catch (IOException e) {
  58. e.printStackTrace();
  59. } finally {
  60. try {
  61. out.close();
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement