Compose-Cropper icon indicating copy to clipboard operation
Compose-Cropper copied to clipboard

Cropped image, not accurate.

Open CharlesMoreira1 opened this issue 1 year ago • 1 comments
trafficstars

I am using your libraries without any issues.

However, I noticed that the cropping is not happening exactly where I want it.

For instance, I'm using your library to crop a part of a text and recognize the text.

But it doesn't crop exactly where I want, and I have to adjust it further down; otherwise, the text doesn't fully appear in the crop.

Do you know how I can solve this?

My code:

@Composable
internal fun ScreenShotCropImage(
    isCrop: Boolean,
    modifier: Modifier = Modifier,
    imageBitmap: ImageBitmap? = rememberImageBitmap(),
    onCropImageResult: (ImageBitmap?) -> Unit,
) {
    val handleSize: Float = LocalDensity.current.run { 20.dp.toPx() }

    val cropProperties by remember {
        mutableStateOf(
            CropDefaults.properties(
                contentScale = ContentScale.Inside,
                cropOutlineProperty = CropOutlineProperty(
                    OutlineType.Rect,
                    RectCropShape(0, "Rect"),
                ),
                aspectRatio = aspectRatios[3].aspectRatio,
                handleSize = handleSize,
                overlayRatio = 0.2f,
                maxZoom = 4f,
            ),
        )
    }
    val cropStyle by remember {
        mutableStateOf(
            CropDefaults.style(drawGrid = false, strokeWidth = 2.dp),
        )
    }

    imageBitmap?.let { image ->
        ImageCropper(
            modifier = modifier
                .fillMaxWidth(),
            imageBitmap = image,
            contentDescription = null,
            cropStyle = cropStyle,
            cropProperties = cropProperties,
            crop = isCrop,
            onCropStart = {},
            onCropSuccess = onCropImageResult,
        )
    }
}

CharlesMoreira1 avatar Nov 29 '23 22:11 CharlesMoreira1

Would you mind sharing the image you want to crop and dimensions of composable? It's difficult to guess without testing it since i never had the issue myself.

SmartToolFactory avatar Nov 30 '23 12:11 SmartToolFactory