writeImageToSavedPhotosAlbum:元数据:completionBlock:

发布于 2024-11-26 12:02:18 字数 1672 浏览 2 评论 0原文

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

-(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];

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

- (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);
            }
    }
}

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

I use the method writeImageToSavedPhotosAlbum:metadata:completionBlock: save taken picture to photo album,code is:

-(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 method getLocation that is get user's current location!That can save success!Then I want to pick taken picture from photo album use UIImagePickerController! Code is :

- (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);
            }
    }
}

Then log the metadata is null.That's why? And how do I get the metadata info which I saved?Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风启觞 2024-12-03 12:02:19

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

请参阅参考文献。查看该页的最后一段。

The metadata of the image will be available only if the sourceType is UIImagePickerControllerSourceTypeCamera.

See Ref. Look at the last paragraph in that page.

猫弦 2024-12-03 12:02:19

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

-(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];
    }
}
...
}

You can take log of metadata with AssetsLibrary framework:

-(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];
    }
}
...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文