0

我已经使用 UIImagePickerController 从 ipad 中的照片库中获取 UIImage。现在我想将该图像保存在与我的应用程序关联并包含已添加图像的目录中。我也得到了目录的url。

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

如何将uiimage保存在指定目录中?

4

1 回答 1

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]; 
于 2013-01-09T12:19:40.440 回答