gpt4 book ai didi

ios - 如何在 uiimagepickercontroller 中创建可裁剪的横幅图像?

转载 作者:行者123 更新时间:2023-11-30 11:04:15 24 4
gpt4 key购买 nike

当我呈现 UIImagePickerController 时,我希望用户能够为用户想要从照片库导入的横幅裁剪 7.8 的比例。

这个问题与创建与 UIImagePickerController 一起使用的自定义裁剪矩形相关的许多问题类似,但所有答案都指向过时的库或过于复杂的库。我想要一些简单的东西。

最佳答案

试试这个:

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

if picker.sourceType == .camera {
if let possibleImage = info["UIImagePickerControllerOriginalImage"] as? UIImage {
// save photo
}
}

if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad && picker.sourceType == .photoLibrary {
if let possibleImage = info["UIImagePickerControllerOriginalImage"] as? UIImage {
newImage = possibleImage
}
} else {
if let possibleImage = info["UIImagePickerControllerEditedImage"] as? UIImage {
newImage = possibleImage
} else if let possibleImage = info["UIImagePickerControllerOriginalImage"] as? UIImage {
newImage = possibleImage
}
}

// logic to manipulate image
print("image size: \(newImage.size)")

let newHeight = 100 // change to preferred height
let scale = 7.8
let newWidth = newImage.size.width

UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight))

newImage.draw(in: CGRect(x: 0, y: 0,width: newWidth, height: newHeight))
newImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
print("image size: \(newImage.size)")

// add logic here
}

关于ios - 如何在 uiimagepickercontroller 中创建可裁剪的横幅图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52921505/

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