How to crop image after taken from UIImagePicker Camera?

荒凉一梦 提交于 2019-12-09 17:41:03

问题


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.


回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/1824287/how-to-crop-image-after-taken-from-uiimagepicker-camera

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