2013-01-09 21 views
0

我已經從使用UIImagePickerController的ipad中的照片庫中獲取UIImage。現在我想將該圖像保存在與我的應用程序關聯的目錄中,幷包含已添加的圖像。我也得到了目錄的網址。如何將uiimage保存在給定nsurl的目錄中?

例如:文件://localhost/Users/administrator/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/31816EF9-AE1E-40DF-93C4-C67A82E4B85B/Documents/7884/Images/

如何將uiimage保存在指定的目錄中?

+0

你想保存圖像在你的Mac或iPhone?該網址是模擬器...請清除。 –

+0

這個網址是模擬器,但我也想在ipad上使用相同的功能。 –

回答

1

使用此代碼將其保存到文檔目錄中。

NSData *pngData = UIImagePNGRepresentation(image); 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsPath = [paths objectAtIndex:0]; 
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.png"]; 
[pngData writeToFile:filePath atomically:YES]; 
+0

非常感謝您的幫助,但問題依然存在。它保存在文檔目錄中,但不會保存圖像到上述url –

+1

中指定的預定子目錄中,首先需要檢查是否有任何目錄不存在,然後創建它,然後保存。 –

+0

問題解決了...... Thanx :) –

相關問題