Skip to content

Instantly share code, notes, and snippets.

@palawer
Created October 28, 2014 15:29
Show Gist options
  • Save palawer/8e5b4d690f97702b5130 to your computer and use it in GitHub Desktop.
Save palawer/8e5b4d690f97702b5130 to your computer and use it in GitHub Desktop.
Save and load image from the app documents
- (void)saveImage:(UIImage *)image
{
if (image != nil) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"test.png"];
NSData *data = UIImagePNGRepresentation(image);
[data writeToFile:path atomically:YES];
}
}
- (UIImage *)loadImage
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:@"test.png"];
UIImage* image = [UIImage imageWithContentsOfFile:path];
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment