How do I save an image to the sandbox - iPhone SDK

后端 未结 2 1528
情歌与酒
情歌与酒 2021-01-28 16:14

I have pulled an image out of the UIImagePicker thingy, and I would like to temporarily save it to the sandbox environment, in either the documents folder, or some other similar

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-28 16:44

    Saving an image:

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

    Loading an image

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

提交回复
热议问题