Reputation: 3695
The default crop function in iPhone photo album
Does any one know how to implement this? I want to crop it before Use button is tapped.
Upvotes: 7
Views: 16220
Reputation: 4038
func cropImageZero(_ completionHandler: (_ img: UIImage)->()){
let image = UIImage(named: "name")
let rect = CGRect(x: 0, y: y, width: width, height: height)
let cgImage = image?.cgImage!.cropping(to: rect)
let imageNew = UIImage(cgImage: cgImage!)
completionHandler(imageNew)
}
Bonnie's answer is useful
Upvotes: 0
Reputation: 1037
If I understand your question correctly, you want to present a UIImagePickerController
with the ability to crop the picture before picking it. This is built-in into UIImagePickerController, just set the allowsEditing
property to YES
. See the documentation for more info http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html.
Upvotes: 5
Reputation: 4953
you can use this to crop the image.
CGRect rect = CGRectMake(some rect);
CGImageRef imageRef = CGImageCreateWithImageInRect([urImageView.image CGImage], rect);
UIImage *cropedImage = [UIImage imageWithCGImage:imageRef];
Upvotes: 2
Reputation: 14314
Try one of these:
https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=crop
You might find an open source that does exactly that
Upvotes: 9