Take and Crop Image in Android
Take and Crop Image in Android
Options.setCompressionFormat(Bitmap.CompressorFormat.PNG);
Options.setHideBottomControls(false);
Options.setFreeStyleCropEnabled(true);
setupFragment(uCorp);
1) Com.android.support:design:27.1.0
2) Com.theartofdev.edmodo:android-image-cropper:2.6.0
3) Click on SyncNow
4) Now the permissions are required:
5) We are asking the user to provide the permissions at run tim:
6) For the external and internal storage of the device
7) Add the activity on the top of the default activity
https://www.androidlearning.com/capture-crop-image-device-camera/
https://www.androidlearning.com/capture-crop-image-device-camera/
Then we’ll create the Intent to crop an image and the following properties will be set
//call the standard crop action intent (the user device may not support it)
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, PIC_CROP);
Finally we can retrieve the cropped image and display it within the app UI.
Inside your “onActivityResult” method, after the “if” statement in which
you check for the “CAMERA_CAPTURE” request code, add an “if else”
statement checking for the “PIC_CROP” code, in which case we are
returning from the crop operation:
Inside this statement, we can retrieve the returned cropped image as follows:
We now have the user’s cropped image as a Bitmap. Let’s display it in the Image
View as follows:
//display the returned cropped image
imageView.setImageBitmap(thePic);