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.
views:
272answers:
2
+1
A:
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;
}
ennuikiller
2009-12-20 04:39:50
Thank you for the quick response time. And accurate answer.
Jaba
2009-12-20 05:29:24
A:
In addition, you don't ever want to save anything into the actual tmp
directory that you want around after the app shuts down. The tmp
directory can be purged by the system. By definition, it exist solely to hold minor files needed only when the app is running.
Files you want to preserve should always go into the documents
directory.
TechZen
2009-12-20 15:13:41