-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Keeping original photo taken from camera results in blank photo. #142
Comments
I cannot reproduce that. |
Basically, I do the following to launch camera intent
public static boolean dispatchCameraIntent(Activity activity, File file, int requestCode) {
Intent takePictureIntent = DisplayUtils.createCameraIntent(activity);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent != null) {
// Save a file: path for use with ACTION_VIEW intents
Uri uri = FileProvider.getUriForFile(activity, IMAGE_FILE_PROVIDER, file);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
List<ResolveInfo> resInfoList = activity.getPackageManager()
.queryIntentActivities(takePictureIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
activity.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
activity.startActivityForResult(takePictureIntent, requestCode);
return true;
} else {
return false;
}
} Then, in if (resultCode == RESULT_OK) {
Uri selectedImage = Uri.fromFile(newFile);
Uri croppedImage = Uri.fromFile(croppedImageFile);
UCrop.Options options = new UCrop.Options();
options.setActiveWidgetColor(ContextCompat.getColor(context, R.color.color_accent));
options.setAllowedGestures(UCropActivity.SCALE, UCropActivity.ALL, UCropActivity.SCALE);
options.setCompressionQuality(80);
options.setMaxBitmapSize(1200);
options.setToolbarColor(ContextCompat.getColor(context, R.color.color_primary));
options.setStatusBarColor(ContextCompat.getColor(context, R.color.color_primary_dark));
UCrop.of(selectedImage, croppedImage).withOptions(options)
.start(this);
} |
This error happens not only with a photo taken from the camera. For example, in the sample app, I choose to crop a random photo, don't touch any settings, go straight to done and I get this. Problem is in BitmapLoadTask class when: final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
if (options.outWidth == -1 || options.outHeight == -1) {
return new BitmapWorkerResult(new IllegalArgumentException("Bounds for bitmap could not be retrieved from the Uri: [" + mInputUri + "]"));
} |
So what's the solution for this? |
I'm looking into the issue, but I have limited amount of time currently. This task has high priority and will be fixed in the next library update. |
Hey guys, ran into the same issue myself. |
An update: Furthermore, when running the SampleActivity in the cloned repo, the error it is coming up with is: 07-29 09:21:58.445 13174-13174/com.yalantis.ucrop.sample E/TransformImageView: onFailure: setImageUri |
As per issue 142 (Yalantis#142), it mentions the issue of files being sent back as null if they make no changes (No cropping). The solution was simply just to check the paths and confirm if they are identical. In the event that the paths are the same, trying to copy one file to the other will cause both files to become null. simply skipping this step if the paths are identical solves that problem. This pull request should fix that issue entirely
Ok! Got it fixed. It was an issue with File copying. Short version, sending the same Uri as both input and output + no cropping caused the code to try to overwrite the other and both ended up being null. This resulted in both files being returned as null and the original getting wiped out. |
Fixed null file sent back (Issue #142)
@PGMacDesign Oh yeah, thanks for the PR -> merged it already. Will be available soon in the new update. |
When you take a photo from camera, and try tapping checkmark icon without making any changes (ratio set to original) to the photo passed to UCropActivity, it results in a blank photo.
The text was updated successfully, but these errors were encountered: