Comments (10)
@vanniktech
Same here. Will this be fixed?
from android-image-cropper.
Facing same issue on my samsung device. I can see the image with crop square but white screen all around.
from android-image-cropper.
Can you reproduce and try to submit a PR which fixes this?
from android-image-cropper.
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.
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.
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.
- 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
- 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.
@vanniktech Is this issue fixed in the latest release?
from android-image-cropper.
Has something changed since my last comment? #599 (comment)
from android-image-cropper.
Same issue here, using a Pixel 6 emulator with API 34.
from android-image-cropper.
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)
- Multiple call of cropImage in loop when we can pick more then one image from gallery HOT 1
- Getting crash while selection of camera cropping only in Android 10
- Question : Is it possible move and scale the picture itself instead of the crop overlay? HOT 5
- v
- Feature Request: Crop by path or region HOT 2
- Prevent CropRect Translation in Image Cropper HOT 5
- Tool bar and its buttons(back, crop etc) is not shown. just white space HOT 3
- [Feature Request] Support for Rounded Rectangle Crop Shape HOT 4
- Integrate the Photo picker tool HOT 1
- Opening camera doesn't allow exiting the activity HOT 1
- How to customize the AlertDialog in Jetpack Compose? HOT 3
- Allow selecting multiple images at a time from the Gallery HOT 3
- Runtime Error Occurs When Revoking Camera Permission During Image Cropping HOT 1
- No toolbar / buttons to confirm the crop HOT 3
- How to block crop event in View ? HOT 2
- Can't see crop and save option getting white screen backgroud HOT 1
- Updating imports from the old library HOT 1
- jcenter to mavencentral
- The CropImageView do not have crop and other buttons HOT 1
- Option bar won't show, preventing from validating crop HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-image-cropper.