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

I set applyMaskToCroppedImage = YES,but the returned image have margins and their alpha is 0. #182

Closed
shenguanjiejie opened this issue Nov 25, 2017 · 19 comments
Assignees
Labels

Comments

@shenguanjiejie
Copy link

shenguanjiejie commented Nov 25, 2017

Then I call UIImageJPEGRepresentation(image,1); the margins will turn to whiteColor. like that
0 _1 tiff

@shenguanjiejie shenguanjiejie changed the title if applyMaskToCroppedImage = YES,but the returned image have clearColor margins. I applyMaskToCroppedImage = YES,but the returned image have clearColor margins. Nov 25, 2017
@shenguanjiejie shenguanjiejie changed the title I applyMaskToCroppedImage = YES,but the returned image have clearColor margins. I set applyMaskToCroppedImage = YES,but the returned image have clearColor margins. Nov 25, 2017
@ruslanskorb
Copy link
Owner

Sorry, but I didn't understand your problem. Please provide more information.

@shenguanjiejie
Copy link
Author

shenguanjiejie commented Nov 27, 2017

😂 Sorry~
RSKImageCropViewController *imageCropVC = [[RSKImageCropViewController alloc] initWithImage:image];
imageCropVC.applyMaskToCroppedImage = YES;

wx20171127-112800 2x

Then I call UIImageJPEGRepresentation(croppedImage,1);

result:
img_cc1acc6b372d-1

@ruslanskorb
Copy link
Owner

Try to set avoidEmptySpaceAroundImage to true.

@shenguanjiejie
Copy link
Author

Not work..

@ruslanskorb
Copy link
Owner

Can you, please, provide your implementation of RSKImageCropViewControllerDataSource methods and the image you trying to crop?

@shenguanjiejie
Copy link
Author

shenguanjiejie commented Nov 27, 2017

PS: self.shouldClipToCircle is false

#imageSize is clipSize🤭
image
image
img_0805

#pragma mark - RSKImageCropViewControllerDelegate
- (CGRect)imageCropViewControllerCustomMaskRect:(RSKImageCropViewController *)controller{
    return [self getRect];
}

- (UIBezierPath *)imageCropViewControllerCustomMaskPath:(RSKImageCropViewController *)controller{
    CGRect rect = [self getRect];
    
    if (self.shouldClipToCircle) {
        return [UIBezierPath bezierPathWithArcCenter:CGRectGetCenter(rect) radius:rect.size.width / 2.0 startAngle:0 endAngle:2*M_PI clockwise:YES];
    }
    
    return [UIBezierPath bezierPathWithRect:rect];
}

- (void)imageCropViewControllerDidCancelCrop:(RSKImageCropViewController *)controller{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)imageCropViewController:(RSKImageCropViewController *)controller willCropImage:(UIImage *)originalImage{
//        int controllerCount = (int)self.navigationController.viewControllers.count;
//        [self.navigationController popToViewController:self.navigationController.viewControllers[controllerCount - 3] animated:YES];
}

- (void)imageCropViewController:(RSKImageCropViewController *)controller didCropImage:(UIImage *)croppedImage usingCropRect:(CGRect)cropRect{
    if (_imagesCompletion) {
        _imagesCompletion([NSArray arrayWithObject:croppedImage]);
    }
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    int controllerCount = (int)self.navigationController.viewControllers.count;
    [self.navigationController popToViewController:self.navigationController.viewControllers[controllerCount - 3] animated:YES];
    
}

#pragma mark 辅助方法

- (CGRect)getRect{
    //
    if (self.imageSize.width == 0 || self.imageSize.height == 0) {
        self.imageSize = CGSizeMake(kScreenWidth, kScreenWidth);
    }
    
    CGFloat scale = MIN(kScreenWidth / self.imageSize.width, kScreenHeight / self.imageSize.height);
    CGSize scaleSize = CGSizeMake(scale * self.imageSize.width, scale * self.imageSize.height);
    CGRect rect = CGRectMake(self.view.centerX - scaleSize.width / 2.0, self.view.centerY - scaleSize.height / 2.0, scaleSize.width, scaleSize.height);
    return rect;
}

@ruslanskorb
Copy link
Owner

@shenguanjiejie Please provide values for getRect method.

@shenguanjiejie
Copy link
Author

image

@ruslanskorb
Copy link
Owner

I mean kScreenWidth, kScreenWidth, self.imageSize.width, self.view.centerX , etc.

@shenguanjiejie
Copy link
Author

shenguanjiejie commented Nov 27, 2017

kScreenWidth = [UIScreen mainScreen].bounds.size.width;
kScreenHeight = [UIScreen mainScreen].bounds.size.height;

image

@ruslanskorb
Copy link
Owner

I just checked the code and the image you provided and I can say that everything should work as you need if you set the value of avoidEmptySpaceAroundImage to YES.

@shenguanjiejie
Copy link
Author

shenguanjiejie commented Nov 27, 2017

Did you zoom the image? Have a try.
img_9d24170fefe4-1

@ruslanskorb
Copy link
Owner

Yes, I did. Everything works properly.

simulator screen shot - iphone 7 - 2017-11-27 at 21 14 57

screen shot 2017-11-27 at 21 15 28

@shenguanjiejie shenguanjiejie changed the title I set applyMaskToCroppedImage = YES,but the returned image have clearColor margins. I set applyMaskToCroppedImage = YES,but the returned image have margins and their alpha is 0. Nov 28, 2017
@shenguanjiejie
Copy link
Author

Sorry about my bad English... You may not understand me. Here is my question with a demo.
https://github.com/shenguanjiejie/RJImagePicker

@ruslanskorb
Copy link
Owner

What problem do you see in these images?

simulator screen shot - iphone x - 2017-11-28 at 10 40 24
screen shot 2017-11-28 at 10 43 33
simulator screen shot - iphone x - 2017-11-28 at 10 40 35

@shenguanjiejie
Copy link
Author

shenguanjiejie commented Nov 28, 2017

😭😭😭 their
image

image

You can try applyMaskToCroppedImage = NO, will no white margins.

@ruslanskorb
Copy link
Owner

@shenguanjiejie Fixed in develop branch. Please check if it works for you.

@shenguanjiejie
Copy link
Author

Perfect! Thanks😀

ruslanskorb added a commit that referenced this issue Nov 29, 2017
…hould always be equal to `size` of `cropRect`.

#182
@ruslanskorb ruslanskorb self-assigned this Nov 29, 2017
@ruslanskorb
Copy link
Owner

Eventually, it is fixed in 1.6.4 🎉
Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants