简体   繁体   English

从相册照片中获取带有元数据的照片文件

[英]Get photo file with metadata from album photo

It is possible to retrieve photo file from the album photo with metadata (IPTC)? 是否可以从带有元数据(IPTC)的相册照片中检索照片文件?
I've tried UIImagePickerController to get UIImage and when I save it to a file, it doesn't contain any metadata information. 我尝试过UIImagePickerController来获取UIImage,当我将其保存到文件中时,它不包含任何元数据信息。
There is a way to get the original photo file with ALAsset library? 有没有一种方法可以使用ALAsset库获取原始照片文件?

I found a solution with AssetsLibrary: 我找到了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]);
    }];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM