如何更改 UIImagePickerController 裁剪框

发布于 2024-07-24 18:49:21 字数 206 浏览 3 评论 0原文

当打开使用 UIImagePickerController 并设置 allowedImageEditing = YES 时; 默认裁剪框为 320x320。 就我而言,我想将横向图像的裁剪框设置为 320x240,将纵向图像设置为 240x320。 但是,我一直无法找到一种方法来更改编辑/裁剪照片时使用的 320x320 框架。 你们有人找到办法了吗?

谢谢!

when opening working with an UIImagePickerController and setting allowsImageEditing = YES; there is a default cropping frame that is 320x320. In my case, I would like to setup that cropping frame to 320x240 for images that are landscape, and 240x320 for images that are portrait. However, I haven't been able to find a way to change that 320x320 frame that is used when editing /cropping a photo. Has any of you found a way to do it?

Thanks!

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

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

发布评论

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

评论(3

东北女汉子 2024-07-31 18:49:21

你必须自己实现它。

选取器仅执行 320x320 裁剪。

因此,请设置

allowedImageEditing = NO;

现在您将获得完整的图像。 然后,您将必须创建一个视图/视图控制器,它将裁剪为您想要的比例。

You have to implement it your self.

The picker only performs 320x320 cropping.

So instead set

allowsImageEditing = NO;

Now you will get the full image back. Then you will have to create a view/view controller that will crop to the proportions you desire.

路还长,别太狂 2024-07-31 18:49:21

您可以尝试 ShittyImageCrop。 它非常适合裁剪为特定的纵横比。 在您的情况下,将其显示为宽高比 4:3(或横向 3:4),如下所示:

let cropVC = ShittyImageCropVC(frame: (self.navigationController?.view.frame)!, image: imageToCrop, aspectWidth: 4, aspectHeight: 3)
self.navigationController?.present(cropVC, animated: true, completion: nil)

之后,您可以使用其他一些代码将其缩放到所需的分辨率(320x240 或 240x320)。

You can try ShittyImageCrop. It's good for cropping to a specific aspect ratio. In your case, present it with aspect ratio 4:3 (or 3:4 in landscape) like this:

let cropVC = ShittyImageCropVC(frame: (self.navigationController?.view.frame)!, image: imageToCrop, aspectWidth: 4, aspectHeight: 3)
self.navigationController?.present(cropVC, animated: true, completion: nil)

After that you can use some other code to just scale it to desired resolution (320x240 or 240x320).

幸福不弃 2024-07-31 18:49:21

这是最新的答案,其中包含必要的手动裁剪代码:手动裁剪

仍然无法逃避艰苦的工作。

This is the more recent answer with the necessary manual cropping code: Manual Crop

There is still no escaping the hard work.

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