Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 views
in Technique[技术] by (71.8m points)

android - Stuck after Cropping Image in Gallery Kotlin Crop Image from Gallery

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.enter image description here

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...