gpt4 book ai didi

ios - 初始填充 UIImagePickerController 的图像

转载 作者:搜寻专家 更新时间:2023-11-01 05:40:22 24 4
gpt4 key购买 nike

在我的 iOS 应用程序中,我想从照片库中抓取图像并将它们裁剪为正方形格式。 UIImagePickerController 很好地处理了这一点,但有一个小问题:当我从库中选择一张横向照片时,它不会填充裁剪区域(对于纵向图像,它会填充)。这允许用户选择一个非正方形区域。 有没有办法强制图像选择器像水平方向一样垂直填充裁剪区域 - 而无需实现我自己的图像选择器?

我的代码:

class AddProfileViewController: UIViewController, UIGestureRecognizerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet weak var profileImageView: EnhancedImageView!
let imagePicker = UIImagePickerController()

override func viewDidLoad() {
super.viewDidLoad()

// ...

imagePicker.delegate = self
}

func profileImageTapped() {
imagePicker.allowsEditing = true
imagePicker.sourceType = .PhotoLibrary
presentViewController(imagePicker, animated: true, completion: nil)
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
// ...
}

func imagePickerControllerDidCancel(picker: UIImagePickerController) {
dismissViewControllerAnimated(true, completion: nil)
}
}

选择一张风景图片,看起来是这样的:

image picker with horizontal image

相反,我希望图像水平和垂直延伸到裁剪框,因此图像选择器将始终返回方形图像。

最佳答案

要结束这个问题 - 这是我解决它的方法:

使用标准图像选择器似乎无法将图像垂直扩展到边界。选项是创建您自己的图像选择器或使用以下解决方法,这在大多数情况下可能就足够了:

如果用户没有放大图像的任何部分,则图像的中心最接近用户的需求,您可以通过在两侧切掉等宽的切片来获得正方形图像。

关于ios - 初始填充 UIImagePickerController 的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31355770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com