Skip to content

CanHub Image Cropper not taking up full crop image container #582

@razer56

Description

@razer56

The problem I am facing is that an image that's 4000x6000 won't fill the cropImageView container fully. While an image that's 1440x3088 will. All I want to do is when a user uploads an image, it always fills the entire cropImageView container. If that image is smaller than the container size, then it should zoom all the way up until it takes up the full container size. How do I achieve this?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.canhub.cropper.CropImageView
            android:id="@+id/cropImageView"
            android:layout_width="match_parent"
            app:cropFixAspectRatio="false"
            android:layout_height="300dp" />

    </LinearLayout>

and here's the code of when I load the image into the cropImageView after I select an image from my camera roll:

private val cropActivityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
    if (result.resultCode == Activity.RESULT_OK) {
        val resultUri = result.data?.data
        if (resultUri != null) {
            // Set the cropped image to the CropImageView
            binding.cropImageView.setImageUriAsync(resultUri)

            // Apply the scale to the CropImageView
            binding.cropImageView.scaleType = CropImageView.ScaleType.CENTER_CROP
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions