quantum
quantum

Reputation: 1420

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.

Upvotes: 6

Views: 11622

Answers (3)

Sriram
Sriram

Reputation: 1049

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.

Upvotes: 1

Giuseppe Frattura
Giuseppe Frattura

Reputation: 133

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

Upvotes: 1

David Maymudes
David Maymudes

Reputation: 5654

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.

Upvotes: 2

Related Questions