Is it possible to access the metadata of an image captured by UIImagePickerController in iOS? I understand this can be done with AssetLibrary framework for images captured by the camera application (or otherwise present in the iPhone photo library), but can a developer access any of the metadata/exif info from within an application right after a user has taken a picture? I'm looking for any type of camera exposure-level info from an image after it has been taken. Thanks!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Apparently, you can access the metadata of an image right after it has been taken. The protocol method that is called by the system after an image has been selected is:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
The NSDictionary argument, info, contains a key: UIImagePickerControllerMediaMetadata
Now if I can figure out how to get the exif tags or any exposure-level information from this to infer basic information about light-level I will be happy. :)
回答2:
updated to iOS 11 with photos framework
Objective - C:
#import <Photos/Photos.h>
- (void)imagePickerController:(UIImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
PHAsset* asset = info[UIImagePickerControllerPHAsset];
[asset requestContentEditingInputWithOptions:nil completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
CIImage *fullImage = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];
NSLog(@"%@", fullImage.properties.description);
}];
[imagePicker dismissViewControllerAnimated:YES completion:nil];
}
You also need the permission of Photo library Usage (NSPhotoLibraryUsageDescription) and then can add the following code to view did load or view did appear
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
switch (status) {
case PHAuthorizationStatusAuthorized:
NSLog(@"PHAuthorizationStatusAuthorized");
break;
case PHAuthorizationStatusDenied:
NSLog(@"PHAuthorizationStatusDenied");
break;
case PHAuthorizationStatusNotDetermined:
NSLog(@"PHAuthorizationStatusNotDetermined");
break;
case PHAuthorizationStatusRestricted:
NSLog(@"PHAuthorizationStatusRestricted");
break;
}
}];