Open manuel-tud opened 8 months ago
Can you reproduce and try to submit a PR which fixes this?
Facing same issue on my samsung device. I can see the image with crop square but white screen all around.
Same issue here. But not just Samsung Phones. Motorola phones too. I don't have direct access to the devices facing the issue.
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.
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.
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
}
}
}
@vanniktech Same here. Will this be fixed?
@vanniktech Is this issue fixed in the latest release?
Has something changed since my last comment? https://github.com/CanHub/Android-Image-Cropper/issues/599#issuecomment-1799260477
Same issue here, using a Pixel 6 emulator with API 34.
Hi, I've an app with 100k+ installs out there. Recently I've updated the target SDK version to 33 without changing anything on the image cropping code. Since that update I receive lots of complaints from users with various (not all) Samsung devices running Android 13 saying that the CIV doesn't load the chosen image and just stays white. I load the image using the setImageUriAsync() method. Unfortunately I was not able to reproduce that bug on my test devices (which are not made by Samsung). I was also not able to reproduce it using Samsung's Test Lab devices. But by the amount of bug report messages (including screenshots showing the behavior) I get, I can say for sure, that there is a bug.
(This could by the same bug mentioned here: https://github.com/CanHub/Android-Image-Cropper/issues/593)