可以从带有元数据 (IPTC) 的相册照片中检索照片文件吗?
我试过 UIImagePickerController 来获取 UIImage ,当我将它保存到文件时,它不包含任何元数据信息。
有没有办法使用 ALAsset 库获取原始照片文件?
问问题
530 次
1 回答
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]);
}];
}
于 2012-04-29T10:52:10.400 回答