-1

我正在使用 ALAssetsLibrary 列出相机胶卷中照片的详细信息。但是如何使用ALAssetsLibrary从相机胶卷中获取特定选定照片的详细信息?

假设我从相机胶卷中选择了 ABC.jpeg。我只想显示 ABC.jpeg 的 exif 详细信息。不是相机胶卷中其他照片的 exif 详细信息。

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

   UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
   self.imageView.image = image;

   NSLog(@"image %@\ninfo: %@",image, info);
   [picker dismissViewControllerAnimated:YES completion:NULL];


    ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
    [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
        if (group) {
            [group setAssetsFilter:[ALAssetsFilter allPhotos]];
            [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
                if (asset){

                    NSDictionary *data = [[asset defaultRepresentation] metadata];
                    NSLog(@"%@",data);
                }
            }];
        }
    } failureBlock:^(NSError *error) {
        NSLog(@"error enumerating AssetLibrary groups %@\n", error);
    }];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    [picker dismissViewControllerAnimated:YES completion:NULL];

}
4

1 回答 1

1

好的,这里是如何使用图像选择器获取媒体选择器资产的代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
   UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
   self.imageView.image = image;

   NSLog(@"media image info: %@", info);

    //use assetLib 
    NSURL *imageURL = [info objectForKey:UIImagePickerControllerReferenceURL];
    if(imageURL) {
        [self getPictureInfoFromAssetURL:imageURL
                                 success:^(NSDictionary*)alInfo {
                                           NSLog(@"asset lib image info: %@", alInfo);
                                 } failure:^(NSError *error) {
                                           NSLog(@"error reading asset lib image info: %@", error);
                                 }];
    }

    [picker dismissViewControllerAnimated:YES completion:NULL];
}

- (void)getPictureInfoFromAssetURL:(NSURL *)url
                           success:(void (^)(NSDictionary *alInfo))success
                           failure:(void (^)(NSError *error))failure {
    ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
    [assetslibrary assetForURL:url
                   resultBlock: ^(ALAsset *myasset) {
                       ALAssetRepresentation *rep = [myasset defaultRepresentation];
                       if(success {
                            success([rep metadata]);
                   }
                  failureBlock: ^(NSError *err) {
                      if (failure) {
                          failure(err);
                      }
                  }];
}
于 2014-07-12T13:03:43.410 回答