2014-11-24 36 views
0

我試圖從圖庫中選擇或通過相機捕獲圖像的路徑。 我一直在使用下面的代碼如何獲取圖片的路徑,從圖庫中選擇或通過相機捕獲

imageView.image= [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
NSData *webData = UIImagePNGRepresentation(imageView.image); 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:png]; 
[webData writeToFile:localFilePath atomically:YES]; 
NSLog(@"localFilePath.%@",localFilePath); 

嘗試,但是當我通過終端檢查「文檔」發現是空文件夾。

回答

1

使用此代碼

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"]; 

imageView.image= [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
NSData *webData = UIImagePNGRepresentation(imageView.image); 
[imageData writeToFile:savedImagePath atomically:NO]; 

NSLog(@"localFilePath.%@",localFilePath); 

如果你還讓它空然後通過NSData的是否正確創建

NSLog(@"webData.%@",webData); 
檢查嘗試
相關問題