gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:22:53 25 4
gpt4 key购买 nike

我正在开发 Apple Photos 扩展。我需要从 PHAsset 获取照片 HDR 和深度效果标志。该扩展似乎只为我提供了临时图像文件的 URL,而不是对 PHAsset 的引用。换句话说,我需要从扩展图像 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) { ......

非常感谢,

皮尤什

最佳答案

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

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的特定常量访问不同的元数据。

关于ios - 如何从 iOS 扩展中的图像 URL 获取对 PHAsset 的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44581253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com