Objective-C iOS Crop Image Using Zoom?

后端 未结 1 1509
执念已碎
执念已碎 2021-02-10 08:52

I am trying to use this code to allow users to zoom and crop their images in my app: https://github.com/iosdeveloper/ImageCropper/tree/master/Classes/ImageCropper

code s

相关标签:
1条回答
  • 2021-02-10 09:32

    I found an answer here that helped me do what I wanted iOS: Cropping a still image grabbed from a UIImagePickerController camera with overlay

    Code Snippet for those interested

    float zoomScale = 1.0 / [scrollView zoomScale];
    
    CGRect rect;
    NSLog(@"contentOffset is :%f,%f",[scrollView contentOffset].x,[scrollView contentOffset].y);
    rect.origin.x = fabsf([scrollView contentOffset].x * zoomScale);
    rect.origin.y = fabsf([scrollView contentOffset].y * zoomScale);
    rect.size.width = fabsf([scrollView bounds].size.width * zoomScale);
    rect.size.height = fabsf([scrollView bounds].size.height * zoomScale);
    
    UIGraphicsBeginImageContextWithOptions( CGSizeMake( rect.size.width,
                                                       rect.size.height),
                                           NO,
                                           0.);
    [[imageView image] drawAtPoint:CGPointMake( -rect.origin.x, -rect.origin.y)
                blendMode:kCGBlendModeCopy
                    alpha:1.];
    UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    0 讨论(0)
提交回复
热议问题