2017-06-22 111 views
-3

我希望使用Objective-C使用didFinishPickingMediaWithInfo的iPhone畫廊獲得圖像路徑如何從畫廊得到圖像路徑中的iOS

+0

的可能的複製[如何得到這在iphone圖庫圖像的路徑(https://stackoverflow.com/questions/13854723 /如何獲取該圖像的路徑 - 這是在iphone畫廊) – Venkat

+0

@WolfPack: - 同樣的問題已被問及先前。在提出任何問題前先搜索。 – Developer

回答

0

你必須創建一個路徑,並在您的應用程序文件夾寫的圖像。

NSString * imageName = [NSString stringWithformat:@"sample_img.png"]; // Imgae name 
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString* documentsDirectory = [paths objectAtIndex:0]; 
NSString* pathToFile = [documentsDirectory stringByAppendingPathComponent:imageName]; 
NSLog(@"Image Path=%@",pathToFile); //This will print the path in console 
[imageData writeToFile:fullPathToFile atomically:NO]; 
+0

我可以像說「gallery/pics/camera/samplepic.png」那樣獲得路徑嗎?像這樣? – WolfPack

+0

沒有它不可能。檢查示例代碼的更新答案 –

1

您可以從信息 DIC在didFinishPickingMediaWithInfo方法得到的所有圖像信息。您可以使用UIImagePickerControllerReferenceURL作爲所選圖像的referenceURL。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
      NSLog(@"Image Dic Description :%@",info.description); 
} 

你從它那裏得到下面的鍵:

UIImagePickerControllerCropRect 
UIImagePickerControllerEditedImage 
UIImagePickerControllerMediaType 
UIImagePickerControllerOriginalImage 
UIImagePickerControllerReferenceURL