-
-
Notifications
You must be signed in to change notification settings - Fork 268
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
CropImage.getActivityResult(data).bitmap = NULL #49
Comments
@Morons how are you calling the library? Another question, how is the output of this logs?
|
One more @Morons can you check if |
I added
D/AppDebug: onActivityResult: data: Intent? is not null D/AppDebug: UpdateBlogFragment: onActivityResult: content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F84/ORIGINAL/NONE/image%2Fjpeg/1954601542 D/AppDebug: onActivityResult: data: Intent? is not null D/AppDebug: CROP: CROP_IMAGE_ACTIVITY_REQUEST_CODE D/AppDebug: UpdateBlogFragment: onActivityResult resultUri: content://za.co.zone.cupio.cropper.fileprovider/my_images/Pictures/cropped6023895601553057964.jpg D/AppDebug: UpdateBlogFragment: onActivityResult resultBitmap Size: null |
So both the original URI and the Changed URI has values -> I can access them by result?.uri |
I can search my Pictures on the device and crop one then ........ |
private fun launchImageCrop(uri: Uri) {
context?.let {
CropImage.activity(uri)
.setGuidelines(CropImageView.Guidelines.ON)
.start(it, this)
}
} |
@Morons I'm trying here, will put some effort to fix this! cannot guarantee will be something fast, sorry for this. One more request, on this lines:
Can you do:
Please! But will try to solve. In any case, if you have time, you can check the library code and try to solve. So we can release =) Will tag here @CanHub/imagecropcollaborators if anyone have time to check this, interesting bug |
CROP_IMAGE_ACTIVITY_REQUEST_CODE -> {
val resultBitmap: Bitmap?
Log.d(BaseBlogFragment.TAG, "CROP: CROP_IMAGE_ACTIVITY_REQUEST_CODE: ${CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE}")
val result = CropImage.getActivityResult(data)
if (result == null) {
Log.d(BaseBlogFragment.TAG, "UpdateBlogFragment: onActivityResult: result = NULL")
}
val resultUri = result?.uri
Log.d(BaseBlogFragment.TAG, "UpdateBlogFragment: onActivityResult resultUri: ${resultUri.toString()}")
resultBitmap = result?.bitmap
Log.d(BaseBlogFragment.TAG, "UpdateBlogFragment: onActivityResult resultBitmap Bitmap: $resultBitmap")
val array = resultBitmap?.toByteArray()
Log.d(BaseBlogFragment.TAG, "UpdateBlogFragment: onActivityResult resultBitmap array: $array")
val resultImage: String = Base64.decode(array, Base64.DEFAULT).decodeToString()
viewModel.setUpdatedUri(resultImage)
} Results AppDebug D/AppDebug: UpdateBlogFragment: onActivityResult: before crop: content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F78/ORIGINAL/NONE/image%2Fwebp/1182126952 D/AppDebug: onActivityResult: data: Intent? is not null D/AppDebug: CROP: CROP_IMAGE_ACTIVITY_REQUEST_CODE: 203 D/AppDebug: UpdateBlogFragment: onActivityResult resultUri: content://za.co.zone.cupio.cropper.fileprovider/my_images/Pictures/cropped7735694781174099916.jpg D/AppDebug: UpdateBlogFragment: onActivityResult resultBitmap Bitmap: null D/AppDebug: UpdateBlogFragment: onActivityResult resultBitmap array: null |
I found this while re-factoring old working code from passing the URi to passing a base64 String for the image. The BUG then would be that Crop does not build the URI correctly and the extraction to bitmap fails, am I correct? Afterthought |
@Morons totally, will work on fixing this ASAP |
Any progress? fixing the bitmap output from CropImage |
Not yet @Morons I'm very busy with normal work and changing jobs. You can jump in if you feel like, otherwise will need to wait a little. I would love to be faster to tackle the bugs, but this code was 2 years without update when I handover so I need to have more time adding it structure so I'm sure I'm not breaking anything with the changes we add. In any case, sorry for the delay, but be sure I'm putting as much time I can to improve it =) |
@Morons I was taking a look with more attention today. We have an issue because a bitmap is a huge data to pass between activities. When you try to get
I was trying to improve this, creating a bitmap, but is too huge for the So the solution for the library is to have a new method that will need the context to get the bitmap from the internal uri. Hope this solve you problem. is coming on next release |
* change stale days * improve documentation * Fix #49 * update changelog
Version 2.0.3
The Issue
CropImage.getActivityResult(data).bitmap = NULL
The Code
Expected behavior
I store my Images for the application in the backend and cashe as base64 strings (Works nice!)
I need the result to be in ByteArray not URI (I actually dont know how to extract a ByteArray from the URI)
So I try and extract the bitmap with .bitmap from th URI and then convert it to a ByteArray with the Extention function I wrote below
My viewModel also expects a base64 string or ByteArray
What happens
D/AppDebug: CROP: CROP_IMAGE_ACTIVITY_REQUEST_CODE
UpdateBlogFragment: onActivityResult resultUri: content://za.co.zone.cupio.cropper.fileprovider/my_images/Pictures/cropped7411884326467077015.jpg
UpdateBlogFragment: onActivityResult resultBitmap Size: null
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
...
Caused by: java.lang.NullPointerException: Attempt to get length of null array
at android.util.Base64.decode(Base64.java:138)
at za.co.zone.cupio.ui.main.blog.UpdateBlogFragment.onActivityResult(UpdateBlogFragment.kt:132)
Code Involved
val resultImage: String = Base64.decode(resultBitmap, Base64.DEFAULT).decodeToString()
Smartphone
AVD Pixel 4 XL API 30 64
The text was updated successfully, but these errors were encountered: