从 UIImagePicker 相机拍摄后如何裁剪图像?

发布于 2024-08-13 05:22:03 字数 121 浏览 3 评论 0原文

我试图让用户拍摄 16x9 宽高比的图像,使其看起来像是漂亮的高清照片。我使用cameraViewOverlay在两端覆盖黑条,但是当拍摄图像时,如何在不调整图像大小或更改图像比例的情况下裁剪顶部和底部?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

誰認得朕 2024-08-20 05:22:03

有很多关于如何缩放/裁剪从相机返回的 UIImage 的帖子,例如这个< /a>.

这比您想象的要棘手一些,因为相机图像是旋转的,所以即使您只是裁剪,您也必须考虑旋转。

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.

哆啦不做梦 2024-08-20 05:22:03

您可以在拍摄图像时将“picker.imageEditing=YES”添加到代码中。
然后你必须在界面构建器中设置 imageView 属性:
图像视图属性->查看->模式->外观适合,或您希望的其他选项

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

陈甜 2024-08-20 05:22:03

检查 Ming Yang 的这个解决方案。
https://github.com/myang-git/iOS-Image-Crop-View

它允许用户通过滑动或拖动图像所需部分周围的矩形边缘来裁剪图像。我认为可以修改此代码以适应您的裁剪需求,无论是自动还是手动。

它是用 Objective-C 编码的。您可能必须使用 Swift 进行编码,或者简单地构建一个桥接头来将 Objective-C 代码与 Swift 代码连接起来。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文