Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
razer56 opened this issue Aug 6, 2023 · 5 comments
Open

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

razer56 opened this issue Aug 6, 2023 · 5 comments

Comments

@razer56
Copy link

razer56 commented Aug 6, 2023

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
        }
    }
}
@vanniktech
Copy link
Contributor

The aspect ratio probably? There are a few options to configure this thing for you though:

https://github.com/CanHub/Android-Image-Cropper/blob/main/cropper/src/main/kotlin/com/canhub/cropper/CropImageOptions.kt

@razer56
Copy link
Author

razer56 commented Aug 6, 2023

The aspect ratio probably? There are a few options to configure this thing for you though:

https://github.com/CanHub/Android-Image-Cropper/blob/main/cropper/src/main/kotlin/com/canhub/cropper/CropImageOptions.kt

I think an easier way to ask my question would be if I had a very small image. Say 50x50 pixels. It's much smaller than the cropImageView, so it would not take the full width or height. Is there a way to automatically zoom in so that it does take up the full width and height of the cropImageView

@vanniktech
Copy link
Contributor

I think you might need to tweak maxZoom but it should be somehow supported yes.

@razer56
Copy link
Author

razer56 commented Aug 6, 2023

I think you might need to tweak maxZoom but it should be somehow supported yes.

I think tweaking scaleX and scaleY will do the trick, but as for my first issue I have an image that's 4000x6000....the aspect ratio is 0.66 and another image that's 1440x3088, its aspect ratio is 0.466. The CropImageView is set to the width of the parent and a height of 300dp. The 1440x3088 takes up the full width and height, while the 4000x6000 does not. I'm not sure why. An image that's 679x452 and has an aspect ratio of 1.50 will also fit the whole width and height of the CropImageView. Any images that are 0.66, 0.75, etc. do not fit the whole width and height of the CropImageView

@vanniktech
Copy link
Contributor

@razer56 did you come back to this problem and found a solution? I still think for now the best solution is to calculcate the zoom factors yourself. You have all of the data (how big is your view/how big is the image).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants