iOS 8 照片框架.访问照片元数据

iOS 8 Photos framework. Access photo metadata(iOS 8 照片框架.访问照片元数据)

本文介绍了iOS 8 照片框架.访问照片元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将 ALAssetsLibrary 替换为 Photos 框架 在我的应用程序中.

I'm looking at replacing ALAssetsLibrary with Photos framework in my app.

我可以很好地检索照片、收藏和资产来源(甚至将它们写回),但看不到任何地方可以访问照片的元数据(例如 {Exif}、{TIFF}、{GPS}等...).

I can retrieve photos, collections, and asset sources just fine (even write them back out), but don't see anywhere to access the metadata of the photos (the dictionaries such as {Exif}, {TIFF}, {GPS}, etc...).

ALAssetsLibrary 有办法.UIImagePickerController 有办法.Photos 也一定有办法.

ALAssetsLibrary has a way. UIImagePickerController has a way. Photos must have a way too.

我看到 PHAsset 有一个 location 属性,可以用于 GPS 字典,但我希望访问所有元数据,包括人脸、方向、曝光,ISO,还有更多.

I see that PHAsset has a location property which will do for the GPS dictionary, but I'm looking to access all of the metadata which include faces, orientation, exposure, ISO, and tons more.

目前苹果处于 beta 2.也许还有更多 API 即将推出?

Currently apple is at beta 2. Perhaps there are more APIs to come ?

更新

没有官方方法可以仅使用照片 API 来做到这一点.

There is no official way to do this using only Photos APIs.

但是,您可以在下载图像数据后读取元数据.有两种方法可以使用 PHImageManagerPHContentEditingInput.

However you can read the metadata after you download the image data. There are a couple of methods to do this using either PHImageManager or PHContentEditingInput.

PHContentEditingInput 方法所需的代码更少,并且不需要您导入 ImageIO.我已将其封装在 PHAsset 类别中.

The PHContentEditingInput method required less code and doesn't require you to import ImageIO. I've wrapped it up in a PHAsset category.

推荐答案

如果你请求一个内容编辑输入,你可以得到完整的图像作为一个CIImage,和CIImage 有一个名为 properties 的属性,它是一个包含图像元数据的字典.

If you request a content editing input, you can get the full image as a CIImage, and CIImage has a property titled properties which is a dictionary containing the image metadata.

示例 Swift 代码:

let options = PHContentEditingInputRequestOptions()
options.networkAccessAllowed = true //download asset metadata from iCloud if needed

asset.requestContentEditingInputWithOptions(options) { (contentEditingInput: PHContentEditingInput?, _) -> Void in
    let fullImage = CIImage(contentsOfURL: contentEditingInput!.fullSizeImageURL)

    print(fullImage.properties)
}

示例 Objective-C 代码:

PHContentEditingInputRequestOptions *options = [[PHContentEditingInputRequestOptions alloc] init];
options.networkAccessAllowed = YES; //download asset metadata from iCloud if needed

[asset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
    CIImage *fullImage = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];

    NSLog(@"%@", fullImage.properties.description);
}];

您将获得所需的 {Exif}、{TIFF}、{GPS} 等字典.

You'll get the desired {Exif}, {TIFF}, {GPS}, etc dictionaries.

这篇关于iOS 8 照片框架.访问照片元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:iOS 8 照片框架.访问照片元数据

基础教程推荐