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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With