unfortunately I'm stuck again for a few hours.
I want to crop an image from the gallery to a certain aspect ratio and paste it into an ImageView. I also want to keep the path of the image in a string.
The problem is that the ImageCropper of my gallery hangs as soon as I crop the image. I get stuck on this screen forever. So the cropped image is not passed back to my app.
Here some important parts of the code:
private fun pickImageFromGallery() {
val intent = Intent(Intent.ACTION_PICK)
intent.type = "image/*"
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 3);
intent.putExtra("aspectY", 2);
intent.putExtra("outputX", 640);
intent.putExtra("outputY", 426);
intent.putExtra("noFaceDetection", true);
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString())
intent.putExtra("return-data", true);
startActivityForResult(intent, IMAGE_PICK_CODE)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK && requestCode == IMAGE_PICK_CODE) {
dev_img.setImageURI(data?.data)
} else {
Toast.makeText(
applicationContext,
"Vorgang abgebrochen.",
Toast.LENGTH_SHORT
).show()
}
}
Without the intent.putExtra commands the image is taken directly from the gallery into the app. Unfortunately then not cropped.
I don't want to use external libraries with my app, so I have hardly found any solutions on the internet. I hope someone recognizes my problem and can help me to correct it. Thank you.
question from:
https://stackoverflow.com/questions/65861413/stuck-after-cropping-image-in-gallery-kotlin-crop-image-from-gallery 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…