[英]How to get a reference to the PHAsset from an image URL in the iOS Extension?
I'm working on an Apple Photos Extension. 我正在开发Apple Photos Extension。 I need to get the photos HDR and Depth Effect flags from the PHAsset. 我需要从PHAsset获取照片HDR和深度效果标志。 The Extension only seems to give me a URL to a temp image file and not a reference to the PHAsset. 该扩展似乎只给我一个指向临时图像文件的URL,而不是给PHAsset的引用。 In other words, I need to get the object of PHAsset from the Extension image URL (or some other way) so I can get the HDR and Depth Effect attributes. 换句话说,我需要从扩展图像URL中获取PHAsset的对象(或通过其他方式),以便获得HDR和深度效果属性。
for item: Any in self.extensionContext!.inputItems {
let inputItem = item as! NSExtensionItem
for provider: Any in inputItem.attachments! {
let itemProvider = provider as! NSItemProvider
if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeImage as String) { ......
Thank you so much, 非常感谢,
Piyush PIYUSH
As far as I know depth (100%) and HDR (not sure :P) are in the Image Properties. 据我所知,图像属性中包含深度(100%)和HDR(不确定:P)。 So do this to get them: 为此,请这样做:
let options = PHContentEditingInputRequestOptions()
//for icloud or itunes
options.isNetworkAccessAllowed = true
//self is the PHAsset Object here this snippet is from an extenstion I made.
self.requestContentEditingInput(with: options, completionHandler: {
(contentEditingInput, _) -> Void in
if contentEditingInput != nil {
if let url = contentEditingInput?.fullSizeImageURL {
//URL is the path of the File in the
if let imageSource = CGImageSourceCreateWithURL(url, nil) {
if let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as Dictionary? {
//Now you can access the metadata here depth should be in exif afaik
}
}
}
}
}
the different Metadatas can be accessed through specific constants of Image I/O 可以通过Image I / O的特定常量访问不同的元数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.