Giter Club home page Giter Club logo

Comments (10)

Alex-Dobrynin avatar Alex-Dobrynin commented on September 23, 2024 4

@vanniktech
Same here. Will this be fixed?

from android-image-cropper.

anmol14dev avatar anmol14dev commented on September 23, 2024 1

Facing same issue on my samsung device. I can see the image with crop square but white screen all around.

from android-image-cropper.

vanniktech avatar vanniktech commented on September 23, 2024

Can you reproduce and try to submit a PR which fixes this?

from android-image-cropper.

Devenom1 avatar Devenom1 commented on September 23, 2024

Same issue here. But not just Samsung Phones. Motorola phones too. I don't have direct access to the devices facing the issue.

from android-image-cropper.

HamzaAkram-shyk avatar HamzaAkram-shyk commented on September 23, 2024

Facing the same issue on my Vivo device. I can see the image with a crop square but a white screen all around. there is no option to go back and get the cropped image's Uri.

from android-image-cropper.

kevschweitzer avatar kevschweitzer commented on September 23, 2024

Same issue here. I Could handle it by implementing a CustomCropImageActivity as stated in documentation and in sample app.

Custom activity code

import android.net.Uri
import android.os.Bundle
import com.canhub.cropper.CropImageActivity
import dac.corp.dactive.databinding.ActivityCustomCropImageBinding

class CustomCropImageActivity : CropImageActivity() {

    private lateinit var binding: ActivityCustomCropImageBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        binding = ActivityCustomCropImageBinding.inflate(layoutInflater)
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        setListener()
        setCropImageView(binding.cropImageView)
    }

    private fun setListener() {
        binding.button.setOnClickListener { cropImage() }
    }

    override fun onPickImageResult(resultUri: Uri?) {
        super.onPickImageResult(resultUri)

        if (resultUri != null) {
            binding.cropImageView.setImageUriAsync(resultUri)
        }
    }
}

Custom Activity Layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".utilities.CustomCropImage.CustomCropImageActivity">

    <com.canhub.cropper.CropImageView
        android:id="@+id/cropImageView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/button"/>

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Accept"
        app:layout_constraintTop_toBottomOf="@id/cropImageView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

And this is the code to start the activity.

  1. You register the activity for result with a new Contract I created to change the Activity that will start (to put my own). I left it below
  2. You launch the activity in some button with the options you want (in my case I only wanted gallery and a square aspect ratio).
private val cropImage = registerForActivityResult(CustomCropImageContract()) { result ->
        if (result.isSuccessful) {
            result.uriContent?.let {
                val bitmap = mapUriToBitmap(it)
                viewModel.setNewPhoto(bitmap)
            }
        }
    }

//In some button you launch the activity
cropImage.launch(
                CropImageContractOptions(null, CropImageOptions(
                    imageSourceIncludeGallery = true,
                    imageSourceIncludeCamera= false,
                    fixAspectRatio = true
                ))
            )

The custom contract here

class CustomCropImageContract : ActivityResultContract<CropImageContractOptions, CropImageView.CropResult>() {
    override fun createIntent(context: Context, input: CropImageContractOptions) = Intent(context, CustomCropImageActivity::class.java).apply {
        putExtra(
            CropImage.CROP_IMAGE_EXTRA_BUNDLE,
            Bundle(2).apply {
                putParcelable(CropImage.CROP_IMAGE_EXTRA_SOURCE, input.uri)
                putParcelable(CropImage.CROP_IMAGE_EXTRA_OPTIONS, input.cropImageOptions)
            },
        )
    }

    override fun parseResult(
        resultCode: Int,
        intent: Intent?,
    ): CropImageView.CropResult {
        val result = intent?.parcelable<CropImage.ActivityResult>(CropImage.CROP_IMAGE_EXTRA_RESULT)

        return if (result == null || resultCode == Activity.RESULT_CANCELED) {
            CropImage.CancelledResult
        } else {
            result
        }
    }
}

from android-image-cropper.

SourabhSuman007 avatar SourabhSuman007 commented on September 23, 2024

@vanniktech Is this issue fixed in the latest release?

from android-image-cropper.

vanniktech avatar vanniktech commented on September 23, 2024

Has something changed since my last comment? #599 (comment)

from android-image-cropper.

omiwrench avatar omiwrench commented on September 23, 2024

Same issue here, using a Pixel 6 emulator with API 34.

from android-image-cropper.

vanniktech avatar vanniktech commented on September 23, 2024

Roll your own activity and just use the CropImageView. Or alternatively use the workaround: #599 (comment)

Long term, I want to get rid of all the contracts & CropImageActivity.

from android-image-cropper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.