gpt4 book ai didi

ios - 单击 iPhone 中的图像后,图像选择器 Controller 无法更改默认裁剪方 block 大小

转载 作者:行者123 更新时间:2023-11-30 10:56:02 25 4
gpt4 key购买 nike

image showing the imagepickercontroller

如图所示,当我从相机拍照时,该方形位置不会改变或调整大小,但它可以在图库中工作。请帮助了解如何更改裁剪方 block 的位置以转到图像的所需部分。

下面给出了使用的代码

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

if let image = info[UIImagePickerControllerOriginalImage] as? UIImage
{
print(image.size)
let croppedImage = info[UIImagePickerControllerEditedImage] as? UIImage
print(croppedImage ?? "")
let cropRect = (info[UIImagePickerControllerCropRect]! as AnyObject).cgRectValue
print(cropRect?.size ?? "")
let _ = UIImage.cropImage(image: image, toRect: CGRect.init(x: 0, y: 0, w: self.imgProfile.bounds.width, h: self.imgProfile.bounds.width))
print(image.size)
self.imgProfile.image = croppedImage
profileImgUpdated = true

}
self.dismiss(animated: true, completion: nil)
}

func openCamera(){
self.imagePicker.sourceType = .camera
self.imagePicker.allowsEditing = true
self.imagePicker.delegate = self
self.present(imagePicker, animated: true)
}

func openPhotoLibrary() {
self.imagePicker.sourceType = .photoLibrary
self.imagePicker.allowsEditing = true
self.imagePicker.delegate = self
self.present(imagePicker, animated: true)
}

最佳答案

Swift 4.2didFinishPickingMediaWithInfo信息:[String:Any]已被废弃,请尝试使用,

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
if let editedImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage {
self.imgProfile.image = editedImage
} else if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
self.imgProfile.image = image
}
self.dismiss(animated: true, completion: nil)
}

要启用编辑,

let picker = UIImagePickerController()
picker.allowsEditing = true

关于ios - 单击 iPhone 中的图像后,图像选择器 Controller 无法更改默认裁剪方 block 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53947630/

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