首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从iOS扩展中的图像URL获取对PHAsset的引用?

如何从iOS扩展中的图像URL获取对PHAsset的引用?
EN

Stack Overflow用户
提问于 2017-06-16 13:10:20
回答 1查看 685关注 0票数 0

我正在开发一个Apple Photos扩展。我需要从PHAsset获取照片HDR和深度效果标志。这个扩展似乎只给了我一个临时图像文件的URL,而不是对PHAsset的引用。换句话说,我需要从扩展图像URL (或其他方式)获取PHAsset的对象,这样才能获得HDR和深度效果属性。

代码语言:javascript
复制
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) { ......

非常感谢,

皮尤什

EN

回答 1

Stack Overflow用户

发布于 2017-06-16 14:01:40

据我所知,深度(100%)和HDR (不确定:P)在图像属性中。因此,请执行以下操作来获取它们:

代码语言:javascript
复制
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
                }
            }
        }
    }
}

可以通过Image I/O的特定常量访问不同的元数据

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44581253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档