Access metadata (exif tags) of image taken by UIIm

2019-01-15 09:16发布

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!

2条回答
干净又极端
2楼-- · 2019-01-15 10:18

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

查看更多
戒情不戒烟
3楼-- · 2019-01-15 10:19

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;
    }
}];
查看更多
登录 后发表回答