メタデータ(IPTC)を使用してアルバム写真から写真ファイルを取得することは可能ですか?
UIImagePickerControllerを使用してUIImageを取得しようとしましたが、ファイルに保存すると、メタデータ情報が含まれていません。
ALAssetライブラリで元の写真ファイルを取得する方法はありますか?
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 に答える