cropImage layout was wrong when use RSKImageCropModeCustom
yangqingren opened this issue · 17 comments
hello, cropImage wrong when use RSKImageCropModeCustom
Reproduction steps:
- Set the example to cropMode:RSKImageCropModeCustom;
- Use CGSize aspectRatio = CGSizeMake (16.0f, 9.0f);
- Rotate 90° and move the picture downward.
Discovery: The picture flashed and the layout was wrong.
Using your example, CGSizeMake (16.0f, 9.0f) (not square),
Rotate and drag down to the bottom;
Should be reproducible.(If it weren't for the problems I caused)
I will solve this problem temporarily by :
-(CGRect)cropRect
{
CGRect maskRect = self.maskRect;
CGFloat rotationAngle = self.rotationAngle;
CGRect rotatedImageScrollViewFrame = self.imageScrollView.frame;
float zoomScale = 1.0 / self.imageScrollView.zoomScale;
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.frame = self.imageScrollView.frame;
scrollView.contentSize = self.imageScrollView.contentSize;
scrollView.contentOffset = self.imageScrollView.contentOffset;
scrollView.transform = CGAffineTransformIdentity;
CGRect imageScrollViewFrame = scrollView.frame;
scrollView.frame = self.maskRect;
...
...
...
// self.imageScrollView.transform = imageScrollViewTransform;
// self.imageScrollView.frame = imageScrollViewFrame;
with a new object to calculate ‘ cropRect’
@yangqingren How do you rotate an image? Programmatically or with a gesture?
with a gesture
@yangqingren Could you record a video of what exactly is wrong?
have been sent ‘ruslan@rsk-lab.com ’
@yangqingren Thanks! Now I noticed the problem.
Hi @yangqingren,
I pushed the fix in develop branch. Could you test it?
The same problem has arisen by the branch #213
You can test this way:
- (void)onAddPhotoButtonTouch:(UIButton *)sender
{
UIImage *photo = [UIImage imageNamed:@"photo"];
RSKImageCropViewController *imageCropVC = [[RSKImageCropViewController alloc] initWithImage:photo cropMode:RSKImageCropModeCustom];
imageCropVC.dataSource = self;
imageCropVC.delegate = self;
imageCropVC.rotationEnabled = YES;
[self.navigationController pushViewController:imageCropVC animated:YES];
}
// Returns a custom rect for the mask.
- (CGRect)imageCropViewControllerCustomMaskRect:(RSKImageCropViewController *)controller
{
CGSize aspectRatio = CGSizeMake(16.0f, 9.0f);
CGFloat viewWidth = CGRectGetWidth(controller.view.frame);
CGFloat viewHeight = CGRectGetHeight(controller.view.frame);
CGFloat maskWidth;
if ([controller isPortraitInterfaceOrientation]) {
maskWidth = viewWidth;
} else {
maskWidth = viewHeight;
}
CGFloat maskHeight;
do {
maskHeight = maskWidth * aspectRatio.height / aspectRatio.width;
maskWidth -= 1.0f;
} while (maskHeight != floor(maskHeight));
maskWidth += 1.0f;
CGSize maskSize = CGSizeMake(maskWidth, maskHeight);
CGRect maskRect = CGRectMake((viewWidth - maskSize.width) * 0.5f,
(viewHeight - maskSize.height) * 0.5f,
maskSize.width,
maskSize.height);
return maskRect;
}
// Returns a custom path for the mask.
- (UIBezierPath *)imageCropViewControllerCustomMaskPath:(RSKImageCropViewController *)controller
{
CGRect rect = controller.maskRect;
CGPoint point1 = CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect));
CGPoint point2 = CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect));
CGPoint point3 = CGPointMake(CGRectGetMaxX(rect), CGRectGetMinY(rect));
CGPoint point4 = CGPointMake(CGRectGetMinX(rect), CGRectGetMinY(rect));
UIBezierPath *rectangle = [UIBezierPath bezierPath];
[rectangle moveToPoint:point1];
[rectangle addLineToPoint:point2];
[rectangle addLineToPoint:point3];
[rectangle addLineToPoint:point4];
[rectangle closePath];
return rectangle;
}
// Returns a custom rect in which the image can be moved.
- (CGRect)imageCropViewControllerCustomMovementRect:(RSKImageCropViewController *)controller
{
if (controller.rotationAngle == 0) {
return controller.maskRect;
} else {
CGRect maskRect = controller.maskRect;
CGFloat rotationAngle = controller.rotationAngle;
CGRect movementRect = CGRectZero;
movementRect.size.width = CGRectGetWidth(maskRect) * fabs(cos(rotationAngle)) + CGRectGetHeight(maskRect) * fabs(sin(rotationAngle));
movementRect.size.height = CGRectGetHeight(maskRect) * fabs(cos(rotationAngle)) + CGRectGetWidth(maskRect) * fabs(sin(rotationAngle));
movementRect.origin.x = CGRectGetMinX(maskRect) + (CGRectGetWidth(maskRect) - CGRectGetWidth(movementRect)) * 0.5f;
movementRect.origin.y = CGRectGetMinY(maskRect) + (CGRectGetHeight(maskRect) - CGRectGetHeight(movementRect)) * 0.5f;
movementRect.origin.x = floor(CGRectGetMinX(movementRect));
movementRect.origin.y = floor(CGRectGetMinY(movementRect));
movementRect = CGRectIntegral(movementRect);
return movementRect;
}
}
@yangqingren Did you test develop branch?
@yangqingren This is what I see - RPReplay_Final1563886346.MP4.zip
You try clicking the choose button.
Hi @yangqingren! Could you check the latest changes in the develop branch?
nice, this problem has been solved in the dev.
@yangqingren Glad to hear it!
@yangqingren Fixed in 2.2.3 🚀 Thank you for reporting!