7

The default crop function in iPhone photo album

enter image description here

Does any one know how to implement this? I want to crop it before Use button is tapped.

enter image description here

Js Lim
  • 3,625
  • 6
  • 42
  • 80
  • You can use following third party repository for this. Those provides UI for cropping and scaling photos in iPhone / iPod Touch apps. - [BJImageCropper](https://github.com/barrettj/BJImageCropper) - [SSPhotoCropperViewController](https://github.com/ardalahmet/SSPhotoCropperViewController) - [ImageCropper](https://github.com/iosdeveloper/ImageCropper) - [BFCropInterface](https://github.com/azzikid/BFCropInterface) A combination of [BJImageCropper](https://github.com/barrettj/BJImageCropper) and [SSPhotoCropperViewController](https://github.com/ardalahmet/SSPhotoCropperViewController) would be a – Meet Doshi Feb 03 '16 at 11:12

4 Answers4

9

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

Stavash
  • 14,244
  • 5
  • 52
  • 80
5

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.

datwelk
  • 1,017
  • 1
  • 9
  • 18
2

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];
Bonnie
  • 4,943
  • 30
  • 34
0
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)
}

image cropping, in Swift 4,

Bonnie's answer is useful

dengApro
  • 3,848
  • 2
  • 27
  • 41