开发者

Access metadata (exif tags) of image taken by UIImagePickerController - iOS/iPhone

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 a开发者_如何学Cfter 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!


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. :)


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;
    }
}];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜