1.1.18.10. fejezet, Kép kivágás

Használjuk a beépített com.android.camera.action.CROP vezérlőt:

    val activityCropLauncher = registerForActivityResult<Intent, ActivityResult>(
        ActivityResultContracts.StartActivityForResult()
    ) { result: ActivityResult? ->
        if (result?.resultCode == RESULT_OK) {
            resetImagePosAndScale()
            viewImage()
        }
    }
 
...
 
    val intent = Intent("com.android.camera.action.CROP")
    val uri = FileProvider.getUriForFile( this, applicationContext.packageName + ".provider", File(stored?.imageFilePath))
    intent.setDataAndType(uri, "image/*")
    intent.putExtra("crop", "true")
    //intent.putExtra("aspectX", 1) //A kivágás arányainak megtartása
    //intent.putExtra("aspectY", 1)
    intent.putExtra("output", uri)
    intent.putExtra("return-data", false);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    try {
        activityCropLauncher.launch(intent)
    } catch (e: Exception) {
        Log.e("MainActivity", e.message.toString())
    }