iOS - how to implement crop image like default photo album?

淺唱寂寞╮ 提交于 2019-12-21 00:46:50

问题


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.


回答1:


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




回答2:


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.




回答3:


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];



回答4:


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



来源:https://stackoverflow.com/questions/16644193/ios-how-to-implement-crop-image-like-default-photo-album

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