https://kotlinlang.org logo
#compose
Title
# compose
j

Justin Xu

03/01/2023, 9:22 PM
I'm using CanHub Image Cropper to select and crop a square image in compose, here is the launcher and invocation:
Copy code
var pfpURI: Uri by remember { mutableStateOf(Uri.EMPTY) }
...
val profilePictureLauncher =
    rememberLauncherForActivityResult(CropImageContract()) { result ->
    if (result.isSuccessful) {
        pfpURI = result.uriContent!!
    }
}
...
// Launch the select/crop image activity
profilePictureLauncher.launch(
    CropImageContractOptions(
        null,
        CropImageOptions(
            guidelines = CropImageView.Guidelines.ON,
            fixAspectRatio = true,
            outputCompressFormat = 
                Bitmap.CompressFormat.PNG
        )
    )
)
However, once I launch the launcher and select the image to crop, the cropping screen shows up but there isn't any button to actually confirm the crop and finish the activity with the cropped URI as result. I put a screenshot below of the screen I get stuck on, is there something I'm missing in the code to confirm the crop? Thanks
b

BaoNguyen

03/02/2023, 8:17 AM
@Justin Xu I introduce you this library which we used in production app. https://github.com/mr0xf00/easycrop
2 Views