SmartToolFactory / Compose-Cropper

🚀🏞✂️ Image cropper that can crop with static, dynamic crop behavior, can use customizable shapes, vectors, and other png files as mask to crop with various customizations
MIT License
331 stars 47 forks source link

Cropped image, not accurate. #34

Open CharlesMoreira1 opened 7 months ago

CharlesMoreira1 commented 7 months ago

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,
        )
    }
}
SmartToolFactory commented 7 months ago

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.