如何将图像保存到沙盒 - iPhone SDK

Jon*_*Jon 0 iphone image file save

我从UIImagePicker中删除了一个图像,我想暂时将它保存到沙盒环境中,在文档文件夹或其他类似的等效文件夹中.但是,我不知道怎么做,请有人帮帮我吗?谢谢

目前图像是UIImage

Cyp*_*ian 12

保存图片:

-(void)saveImage:(UIImage*)image{
    NSString  *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/someImageName.png"];

   [UIImagePNGRepresentation(image) writeToFile:imagePath atomically:YES];

}
Run Code Online (Sandbox Code Playgroud)

加载图片

-(UIImage)loadImage{

   NSString  *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/someImageName.png"];

   UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
}
Run Code Online (Sandbox Code Playgroud)