I want to crop selected image from gallery to square image. I have button select_photo and image_view that displays photo. When user click on button it opens user gallery. I have tried several options that I have found on the web.
This is my code that create Intent and open gallery.
private fun choosePhotoFromGallary() {
val galleryIntent = Intent(Intent.ACTION_PICK)
galleryIntent.apply {
type = "image/*"
putExtra("crop", "true")
putExtra("outputX", 250)
putExtra("outputY", 250)
putExtra("scale", true)
putExtra("aspectX", 1)
putExtra("aspectY", 1)
putExtra("return-data", true)
}
startActivityForResult(galleryIntent, GALLERY_REQUEST_CODE)
}
I use onActivityResult() to get my data back from the Intent.
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == GALLERY_REQUEST_CODE) {
if(resultCode == Activity.RESULT_OK) {
photoImageView.setImageURI(data?.data)
}
}
}
But i have no "cropping menu" available. So chosen photo is unchanged. I want it to be square so i need cropping. How can i launch "cropping menu" so user can crop the image?