2009-08-12 5 views
2

UIImagePickerView 컨트롤러는 이미지 NSData을 반환합니다.UIImagePickerView 컨트롤러 - 이미지 경로 - 아이폰

내 요구 사항은 이미지의 경로를 varchar 데이터 형식으로 저장하는 것입니다.

UIImagePickerView UIImagePickerView에서 이미지를 선택한 후 iPhone의 Photo Gallery에서 선택한 이미지의 전체 경로를 얻으려면 어떻게해야합니까?

내 응용 프로그램 내 응용 프로그램 내에서 이미지를 저장하는 것에 대해 걱정할 필요가 없습니다. 이미지는 이미 iPhone의 사진 갤러리에 저장되어 있습니다.

미리 감사드립니다.

답변

7

이것은 불가능합니다. UIImagePickerController는 UIImage*을주고, NSData으로 변환하고 로컬 샌드 박스에 저장해야합니다. 보안상의 이유로 사용자의 사진 갤러리에있는 이미지에 액세스 할 수있는 SDK 승인 방법이 없습니다.

SDK 3.0을 사용 중이라고 가정하면 피커를 반환하여 응용 프로그램의 문서 디렉토리에있는 디스크에 저장하는 기능이 있습니다 (어딘가에 약간의 실수가있을 수 있음).

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    // Dismiss the picker 
    [[picker parentViewController] dismissModalViewControllerAnimated:YES]; 

    // Get the image from the result 
    UIImage* image = [info valueForKey:@"UIImagePickerControllerOriginalImage"]; 

    // Get the data for the image as a PNG 
    NSData* imageData = UIImagePNGRepresentation(image); 

    // Give a name to the file 
    NSString* imageName = @"MyImage.png"; 

    // Now, we have to find the documents directory so we can save it 
    // Note that you might want to save it elsewhere, like the cache directory, 
    // or something similar. 
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString* documentsDirectory = [paths objectAtIndex:0]; 

    // Now we get the full path to the file 
    NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName]; 

    // and then we write it out 
    [imageData writeToFile:fullPathToFile atomically:NO]; 
} 
+0

의미는 - 이미지가 복제 됨 - 이미지는 두 위치, 내 애플리케이션 및 iPhone에 저장됩니다. 그렇습니까? –

+1

예. 불행하게도 Apple은 원본 이미지를 가져올 방법을 제공하지 않습니다. 이 작업은 비공식적으로 사용자의 사진 갤러리 (수동/비공개 장소)를 통해 직접보고 비용이 많이 드는 이미지를 찾기 위해 시도 할 수 있습니다. NSData로 이미지를 디스크에 저장하면 거대한 이미지 (수 메가 픽셀)도 너무 많은 공간을 차지해서는 안됩니다. 그래서 현실에서는 거의 문제가되지 않습니다. – Itay

+0

도와 주시겠습니까, 그 응용 프로그램에 그 UIImage를 저장하는 방법? –