如何从UIImage中提取图像文件名



我有<UIImage: 0x6040000b9800> , {1668, 2500} 名称用于从图库中拍摄的照片。但是我需要字符串中的图像名称。有人帮我解决 swift 4 吗?我在下面给出了代码:

extension PhotoViewController: ImagePickerDelegate {
func wrapperDidPress(_ imagePicker: ImagePickerController, images: [UIImage]) {
}
func doneButtonDidPress(_ imagePicker: ImagePickerController, images: [UIImage]) {
self.image = images[0]

let navigati:PhotoDescriptorController = storyboard!.instantiateViewController(withIdentifier: StoryBoard.PhotoDescriptorController) as! PhotoDescriptorController
navigati.imageDest = self.image
self.navigationController?.pushViewController(navigati, animated: true)
imagePicker.dismiss(animated: true, completion: nil)
}
func cancelButtonDidPress(_ imagePicker: ImagePickerController) {
imagePicker.dismiss(animated: true, completion: nil)
}

您是否尝试过使用Photo框架来获取图像名称?

请参阅此示例。

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let asset = info[UIImagePickerControllerPHAsset] as? PHAsset {
let assetResources = PHAssetResource.assetResources(for: asset)
print(assetResources.first!.originalFilename)
}
dismiss(animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let picURL = info[UIImagePickerControllerReferenceURL] as? URL {
let imgData = PHAsset.fetchAssets(withALAssetURLs: [picURL], options: nil)
let asset = imgData.firstObject
print(asset?.value(forKey: "filename"))
}
dismiss(animated: true, completion: nil)
}

最新更新