2011-07-28 8 views
0

私は、メソッドwriteImageToSavedPhotosAlbumを使用します。メタデータ:completionBlockは:写真をアルバムに撮影した画像を保存し、コードは次のとおりです。writeImageToSavedPhotosAlbum:メタデータ: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); 
      } 
    } 
} 

ログはメタデータがnullです。その理由は何ですか?そして私が保存したメタデータ情報を入手するにはどうすればいいですか?ありがとう!

答えて

0

イメージのメタデータは、sourceTypeがUIImagePickerControllerSourceTypeCameraの場合にのみ使用できます。

See Ref。そのページの最後の段落を見てください。

+0

は私がたsourceTypeとして利用可能な画像のメタデータをされて知っている、あなたに真実を伝えるUIImagePickerControllerSourceTypeCamera.But私は、メタデータ情報を取得する方法がわかりません?どちらの方法を使うことができますか? – scofield

0

あなたは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]; 
    } 
} 
... 
} 
関連する問題