使用相册照片中的元数据获取照片文件

时间:2012-04-27 14:24:42

标签: iphone ios uiimage

可以从带有元数据(IPTC)的相册照片中检索照片文件吗? 我已经尝试过UIImagePickerController来获取UIImage,当我将它保存到文件时,它不包含任何元数据信息。
有一种方法可以使用ALAsset库获取原始照片文件吗?

1 个答案:

答案 0 :(得分:1)

我找到了AssetsLibrary的解决方案:

- (void)savePhoto:(NSURL*) url <br
{
    NSString *applicationDocumentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
    [assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) {
        NSString* originalFileName = [[asset defaultRepresentation] filename];
        NSString *path = [applicationDocumentsDir stringByAppendingPathComponent:originalFileName];
        ALAssetRepresentation *rep = [asset defaultRepresentation];
        Byte *buffer = (Byte*)malloc(rep.size);
        NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
        NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
        //NSLog(@"%@",data);
        [data writeToFile:path atomically:YES];
    } failureBlock:^(NSError *err) {
        NSLog(@"Error: %@",[err localizedDescription]);
    }];
}