ios - 使用 UIImagePickerControllerDelegate 获取照片的图像 URL

标签 ios swift uiimagepickercontroller

我正在使用 UIImagePickerController 来选择图像。我也希望获得本地路径。

我正在使用

对相册中的图像执行此操作

info[UIImagePickerController.InfoKey.imageURL] 为?网址

对于使用相机的图像,这是nil

是否可以使用UIImagePickerControllerDelegate捕获此路径?

最佳答案

是的,但是用另一个键:

info[UIImagePickerController.InfoKey.originalImage] as? UIImage

info[UIImagePickerController.InfoKey.editedImage] as? UIImage

请注意,那里的对象将是 UIImage 类型,而不是 URL

相机照片默认不保存,并且没有本地路径。所以需要你自己保存。例如:

if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
    try? image.pngData()?.write( .... )
}

关于ios - 使用 UIImagePickerControllerDelegate 获取照片的图像 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58841857/

相关文章:

ios - 将数据传递给 BTsidemenu

ios - 从应用程序向 ARKit 添加引用图像

ios - 从 iOS(设备和模拟器)中删除自签名证书

ios - 在 swift 中附加或连接音频文件

objective-c - 使用现有 View 作为UIImagePickerController的cameraOverlayView

ios - swift 4 : UIImagePicker delegate methods not being called

ios - 获取 NSInvalidArgumentException',原因 : 'Cannot create an NSPersistentStoreCoordinator with a nil model'

ios - 如何在Xcode中进行Wi-Fi文件共享

ios - swift 2 : Cannot subscript a value of type '[GKScore]?'

ios - 在 UIImagePickerController 中强制横向