使用 UIImagePickerControllerDelegate 获取照片的图像 URL
Get Image URL of photo with UIImagePickerControllerDelegate
我正在使用 UIImagePickerController
到 select 个图像。我也希望得到本地路径。
我正在使用
对相册中的图像执行此操作
info[UIImagePickerController.InfoKey.imageURL] as? URL
然而,如果是使用相机拍摄的图像,则为 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( .... )
}
我正在使用 UIImagePickerController
到 select 个图像。我也希望得到本地路径。
我正在使用
对相册中的图像执行此操作info[UIImagePickerController.InfoKey.imageURL] as? URL
然而,如果是使用相机拍摄的图像,则为 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( .... )
}