Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to crop image after taken from UIImagePicker Camera?

I'm trying to allow the user to take 16x9 aspect ratio images to look like they are nice HD photos. I'm using the cameraViewOverlay to overlay black bars on both ends, but when the image is taken, how do I crop the top and bottom without resizing or changing the scale of the image?

Thanks.

like image 624
quantum Avatar asked Dec 01 '09 06:12

quantum


3 Answers

There are various posts around on how to scale/crop a UIImage you get back from the camera, like this one.

It's a little trickier than you'd expect, because camera images are rotated, so you have to think about rotations even if you're just cropping.

like image 97
David Maymudes Avatar answered Nov 11 '22 14:11

David Maymudes


you can add "picker.imageEditing=YES" to your code when you take the image. Then you have to set the imageView proprieties in the interface builder: Image View Attributes -> View -> Mode -> Aspect fit, or other option as you wish

like image 22
Giuseppe Frattura Avatar answered Nov 11 '22 15:11

Giuseppe Frattura


Check this solution by Ming Yang. https://github.com/myang-git/iOS-Image-Crop-View

It lets the user crop the image by sliding or dragging the edges of a rectangle around the required portion of the image. I presume this code can be modified to suit your cropping need be it automatic or manual.

It is coded in Objective-C. You may have to either code it in Swift or simply build a bridging header to connect the Objective-C code with Swift code.

like image 44
Sriram Avatar answered Nov 11 '22 13:11

Sriram