我正在使用ALAssetsLibrary列出相机中存在的照片的详细信息。但是如何使用 ALAssetsLibrary 从cameraroll获取特定选定照片的详细信息?
假设我从cameraroll中选择了ABC.jpeg。我想显示只有ABC.jpeg的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];
}
答案 0 :(得分: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);
}
}];
}