首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >writeImageToSavedPhotosAlbum:metadata:completionBlock:

writeImageToSavedPhotosAlbum:metadata:completionBlock:
EN

Stack Overflow用户
提问于 2011-07-28 13:24:16
回答 2查看 3.9K关注 0票数 0

我使用的方法是writeImageToSavedPhotosAlbum:metadata:completionBlock:将拍摄的图片保存到相册,代码是:

代码语言:javascript
复制
-(void)savePhotoToAlbum{    
   CGImageRef imageRef=[imageView image].CGImage;

NSDictionary *currentDic=[self getLocation];
NSDictionary *metadata=[NSDictionary dictionaryWithDictionary:currentDic];

ALAssetsLibrary *library=[[ALAssetsLibrary alloc] init];

[library writeImageToSavedPhotosAlbum:imageRef metadata:metadata completionBlock:^(NSURL *assetURL,NSError *error){
   if(error == nil) 
    {
        UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:nil message:@"Save success!" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
        [alertView show];
        [alertView release];
    } 
    else 
    {
        UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:nil message:@"Save failure!" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
        [alertView show];
        [alertView release];
    }
}];
[library release];

}获取用户当前位置的.The方法getLocation!这可以保存成功!然后我想使用UIImagePickerController从相册中选择拍摄的照片!代码为:

代码语言:javascript
复制
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{   if([picker sourceType]==UIImagePickerControllerSourceTypeSavedPhotosAlbum)//picker image delegate
    {
        NSString *mediaType=[info objectForKey:UIImagePickerControllerMediaType];
        if([mediaType isEqualToString:@"public.image"])
        {
            NSDictionary *metadata=[info objectForKey:UIImagePickerControllerMediaMetadata];
            NSLog(@"%@",metadata);
            }
    }
}

那么记录元数据为空。这就是为什么?如何获取我保存的元数据信息?谢谢!

EN

回答 2

Stack Overflow用户

发布于 2011-07-28 14:19:45

只有当sourceType为UIImagePickerControllerSourceTypeCamera时,图像的元数据才可用。

See Ref。看那一页的最后一段。

票数 0
EN

Stack Overflow用户

发布于 2011-09-21 17:44:18

您可以使用AssetsLibrary框架记录元数据:

代码语言:javascript
复制
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
...
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
    NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
    if (url) {
        ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) {
            CLLocation *location = [myasset valueForProperty:ALAssetPropertyLocation];

            NSLog(@"\n\n\n____________________________\n");
            NSLog(@"ORIENTATION: %@\n",[myasset valueForProperty:ALAssetPropertyOrientation]);
            NSLog(@"LOCATION: %@\n",[myasset valueForProperty:ALAssetPropertyLocation]);
            NSLog(@"DATE: %@\n",[myasset valueForProperty:ALAssetPropertyDate]);
            NSLog(@"Duration: %@\n",[myasset valueForProperty:ALAssetPropertyDuration]);
            NSLog(@"TYPE: %@\n",[myasset valueForProperty:ALAssetPropertyType]);
            NSLog(@"\n____________________________\n\n\n");

                            //take coordinates only
            CLLocationCoordinate2D coordinate = [location coordinate];
            strCoord = [NSString stringWithFormat:@"long: %f; lat: %f;", coordinate.latitude, coordinate.longitude];
            NSLog(@"%@", strCoord);
            // location contains lat/long, timestamp, etc
            // extracting the image is more tricky and 5.x beta ALAssetRepresentation has bugs!

        };
        ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror) {
            NSLog(@"cant get image - %@", [myerror localizedDescription]);
        };
        ALAssetsLibrary *assetsLib = [[ALAssetsLibrary alloc] init];
        [assetsLib assetForURL:url resultBlock:resultblock failureBlock:failureblock];
    }
}
...
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6854453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档