Created
October 28, 2014 15:29
-
-
Save palawer/8e5b4d690f97702b5130 to your computer and use it in GitHub Desktop.
Save and load image from the app documents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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