如何在swift3中从库的PHAsset中获取图像文件名
Posted
技术标签:
【中文标题】如何在swift3中从库的PHAsset中获取图像文件名【英文标题】:How get image filename from PHAsset of library in swift3 【发布时间】:2018-03-07 07:17:49 【问题描述】:我正在使用 QBImagePicker。我试图获取图像文件名,但这非常困难。我能为此做些什么?我不知道。
func qb_imagePickerController(_ imagePickerController: QBImagePickerController!, didFinishPickingAssets assets: [Any]!)
let requestOptions = PHImageRequestOptions()
requestOptions.resizeMode = PHImageRequestOptionsResizeMode.exact
requestOptions.deliveryMode = PHImageRequestOptionsDeliveryMode.highQualityFormat
// this one is key
requestOptions.isSynchronous = true
for asset in assets
if ((asset as AnyObject).mediaType == PHAssetMediaType.image)
PHImageManager.default().requestImage(for: asset as! PHAsset, targetSize: PHImageManagerMaximumSize, contentMode: PHImageContentMode.default, options: requestOptions, resultHandler:
(pickedImage, info) in
self.selectImage.image = self.resizeImage(getImageView: self.selectImage, originImage: pickedImage!)
)
imagePickerController.dismiss(animated: true, completion: nil)
【问题讨论】:
【参考方案1】:试试这个
if let fileName = Asset.value(forKey: "filename") as? String
print(fileName)
【讨论】:
【参考方案2】:let originalName = PHAssetResource.assetResources(for: asset).first?.originalFilename
print("original File name \(originalName)")
【讨论】:
您好,请详细说明您的回答,说明为什么这可以解决 OP 的问题。这将有助于 OP 和该网站的未来访问者。谢谢!以上是关于如何在swift3中从库的PHAsset中获取图像文件名的主要内容,如果未能解决你的问题,请参考以下文章
如何从 UIImagePickerController 获取图像文件名
iOS Photokit - PHAsset pixelWidth 和 pixelHeight 与高分辨率图像不匹配