Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I save and read an image to my temp folder when quitting and loading my app

I want to save and read a UIImage to my temp folder when my app closes and then load and delete it when the app loads. How do I accomplish this. Please help.

like image 599
Jab Avatar asked Dec 20 '09 04:12

Jab


1 Answers

These methods allow you to save and retrieve an image from the documents directory on the iphone

+ (void)saveImage:(UIImage *)image withName:(NSString *)name {
    NSData *data = UIImageJPEGRepresentation(image, 1.0);
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:name];
    [fileManager createFileAtPath:fullPath contents:data attributes:nil];
}

+ (UIImage *)loadImage:(NSString *)name {
    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:name];    
    UIImage *img = [UIImage imageWithContentsOfFile:fullPath];

    return img;
}
like image 62
ennuikiller Avatar answered Oct 20 '22 18:10

ennuikiller