【发布时间】:2017-10-16 23:24:11
【问题描述】:
我想我有一个类似的问题,如 this 其他问题的标题所暗示的,但接受的答案根本不是我需要的。
我想“强制”用户使用方形图像。 Currently, when choosing a horizontally "longer" image (landscape image), one could theoretically make a selection with black bars top and bottom which results in a selected image that is NOT squared.
这是我的代码:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
var selected: UIImage?
if let img = info[UIImagePickerControllerEditedImage] as? UIImage {
selected = img
selected = UIImage.imgToSquare(image: selected)
doSomethingWithImage(selected!)
}
picker.dismiss(animated: true, completion: nil)
}
UIImage.imgToSquare(image: UIImage) 是我拥有并用作临时后备的扩展,但如果“最大捏合/缩小”给出方形图像,它会更加优雅。
对于将其标记为重复的人..这是以哪种方式重复的?我在整个互联网上都找不到解决方案,而且您链接的内容与 UIImagePickerController 无关....
我已经说过我可以使用我的扩展程序 (UIImage.imgToSquare(image: UIImage)) 将图像裁剪为正方形......
但我想要的是图像 SELECTION 始终是方形的。
我会附上截图。
我有什么:
我想要什么:
(第二个 - 我想要的 - 仍然可以水平滚动)
【问题讨论】:
-
您为什么不简单地删除允许编辑的选项并在您的 imageView 上使用内容模式 scaleAspectFill。或者实现自己的裁剪
-
因为我希望我的用户选择他的图像中不一定在中心的正方形部分。也许我可以在 UIImagePicker 上设置一些只允许正方形选择的东西(顶部和底部没有黑色部分)?
标签: ios swift uiimage uiimagepickercontroller