2011-07-28 2 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

원본 형식이 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]; 
    } 
} 
... 
}