Images downloaded from the Internet, if you want to achieve permanent storage, need to be saved to files or databases, the current file io is the fastest, haha
The core code is as follows:
-(NSString *) findUniqueSavePath
{
Int I = 1;
NSString * path;
Do {
// This loop knows how to save a new image ......
Path = [NSString stringWithFormat: @ "% @/Documents/IMAGE _ % 04d. PNG", NSHomeDirectory (), I ++];
} While ([[NSFileManager defaultManager] fileExistsAtPath: path]);
Return path;
}
-(Void) imagePickerController :( UIImagePickerController *) picker didFinishPickingMediaWithInfo :( NSDictionary *) info
{
UIImage * image = [info objectForKey: @ "UIImagePickerControllerOriginalImage"];
[Self dismissModalViewControllerAnimated: YES];
[Picker release];
// Png and jpeg modes for file writing
// [UIImageJPEGRepresentation (image, 1.0f) writeToFile: [self findUniqueSavePath] atomically: YES];
[UIImagePNGRepresentation (image) writeToFile: [self findUniqueSavePath] atomically: YES];
// Set the current window to Beijing
SETIMAGE (image );
// Display the list of currently written files
CFShow ([[NSFileManager defaultManager] directoryContentsAtPath: [NSHomeDirectory () stringByAppendingString: @ "/Documents"]);
}
----------------------
For how to read images in a file, see my previous blog.
Author sdhjob