Skip to content
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

[FIX] Poor image quality after cropping #825

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi

//Light Blue 500
private final String DEFAULT_WIDGET_COLOR = "#03A9F4";
private int width = 200;
private int height = 200;
private int width = 0;
private int height = 0;

private Uri mCameraCaptureURI;
private String mCurrentPhotoPath;
Expand Down Expand Up @@ -610,11 +610,15 @@ private void startCropping(Activity activity, Uri uri) {
configureCropperColors(options);
}

UCrop.of(uri, Uri.fromFile(new File(this.getTmpDir(activity), UUID.randomUUID().toString() + ".jpg")))
.withMaxResultSize(width, height)
.withAspectRatio(width, height)
.withOptions(options)
.start(activity);
UCrop uCrop = UCrop
.of(uri, Uri.fromFile(new File(this.getTmpDir(activity), UUID.randomUUID().toString() + ".jpg")))
.withOptions(options);

if (width > 0) {
uCrop.withMaxResultSize(width, height).withAspectRatio(width, height);
}

uCrop.start(activity);
}

private void imagePickerResult(Activity activity, final int requestCode, final int resultCode, final Intent data) {
Expand Down
6 changes: 1 addition & 5 deletions ios/src/ImageCropPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -839,11 +839,7 @@ - (void)imageCropViewController:(RSKImageCropViewController *)controller
didCropImage:(UIImage *)croppedImage
usingCropRect:(CGRect)cropRect {

// we have correct rect, but not correct dimensions
// so resize image
CGSize resizedImageSize = CGSizeMake([[[self options] objectForKey:@"width"] intValue], [[[self options] objectForKey:@"height"] intValue]);
UIImage *resizedImage = [croppedImage resizedImageToFitInSize:resizedImageSize scaleIfSmaller:YES];
ImageResult *imageResult = [self.compression compressImage:resizedImage withOptions:self.options];
ImageResult *imageResult = [self.compression compressImage:croppedImage withOptions:self.options];

NSString *filePath = [self persistFile:imageResult.data];
if (filePath == nil) {
Expand Down