Objective-C iOS Crop Image Using Zoom?

一笑奈何 提交于 2019-12-03 08:25:26
Evan Layman

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();
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!